Re: [PHP] Newbie Help (CLASS WAR!)

2001-07-27 Thread George Pitcher

Have a look at:

http://www.phpbuilder.com/columns/luis2420.php3

HTH

George, still a newbie after a week on php
- Original Message -
From: CC Zona [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, July 27, 2001 11:25 AM
Subject: Re: [PHP] Newbie Help (CLASS WAR!)


 In article [EMAIL PROTECTED],
  [EMAIL PROTECTED] (Brian White) wrote:

  There are times when I would really like to be able to do:
 
  class A
  {
   function DoStuff()
   {
  .
   }
  }
 
  class B extends A
  {
   function DoStuff()
   {
  .
  $super-DoStuff(); // Calls the function in A
   }
  }

 Maybe I'm misunderstanding you, but isn't that what the A::DoStuff()
syntax
 does?

 --
 CC

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Newbie Help (CLASS WAR!)

2001-07-26 Thread Brian White


I use classes a lot and don't have this problem. This is because
the names of the class ( and thus the constructor name ) tends to be a noun
and otherfunctions tend to be verbs, so I am don't have this kind of clash.

I am VERY glad that PHP has classes and I use them alot.

However 

rant_mode

My biggest bug-bear with classes in PHP is the lack of a super operator
There are times when I would really like to be able to do:

class A
{
 function DoStuff()
 {
.
 }
}

class B extends A
{
 function DoStuff()
 {
.
$super-DoStuff(); // Calls the function in A
 }
}

A super operator could allow a fixed name constructor ( like the 
__new__ in Python )
and the parent constructor could be called using super, which would 
eliminate
Matthew's problem.

/rant_mode


At 08:47 26/07/2001 +0800, Matthew Schubert wrote:
I was reading through the PHP manual and got to the section on constructors.

snip

class A {
   function A() {
 echo I am the constructor of A.br\n;
   }

   function B() {
 echo I am a regular function named B in class A.br\n;
 echo I am not a constructor in A.br\n;
   }
}

class B extends A {
   function C() {
 echo I am a regular function.br\n;
   }
}

// This will call B() as a constructor.
$b = new B;




In PHP 3, the function B() in class A will suddenly become a constructor in
class B, although it was never intended to be. The rule in PHP 3 is: 'A
constructor is a function of the same name as the class.'. PHP 3 does not
care if the function is being defined in class B, or if it has been
inherited.

This is fixed in PHP 4 by modifying the rule to: 'A constructor is a
function of the same name as the class it is being defined in.'. Thus in PHP
4, the class B would have no constructor function of its own and the
constructor of the base class would have been called, printing 'I am the
constructor of A.br'.
/snip

It says that when a new class B was made, that the class B would have no
constructor, because the function B() was in the base class. Instead the
class B was supposed to derive it's constructor from class A and output 'I
am the constructor of A.br'

When I tried this script, this did not happen and the Function B() was
called as the constructor of class B, even though the function was in the
base class...can anyone help to clear up this matter?
thanx




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-
Brian White
Step Two Designs Pty Ltd - SGML, XML  HTML Consultancy
Phone: +612-93197901
Web:   http://www.steptwo.com.au/
Email: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]