note 49358 deleted from language.oop.constructor by danbrown
| From: | danbrown@php.net | Date: | Sat, 07 Nov 2009 18:57:31 +0000 |
| Subject: | note 49358 deleted from language.oop.constructor by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162529@lists.php.net to get a copy of this message | ||
Note Submitter: john dot q dot webmaster at gmail dot com
----
When testing the final example, I'm getting conflicting results with what the manual says.
-----
In PHP 3, the function B() in class A will suddenly become a constructor in class B, although it was
never intended to be....
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 />'.
-----
I've just tested this on two systems, PHP (module) 4.3.7 and (CGI) 4.3.10. BOTH of them print
out the contents of B() when creating a new object of B. This is contrary to the manual, which says
this should only happen in PHP 3.
However, when testing the second to last example (where B() has no constructor), the behavior
indicated for PHP 4 DOES happen; a constructor is called for 'new B', and it prints
"I am the constructor of A.<br />".
What's happening here?