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]

Reply via email to