note 49358 added to language.oop.constructor
| From: | john dot q dot webmaster at gmail dot com | Date: | Tue, 25 Jan 2005 13:55:52 +0000 |
| Subject: | note 49358 added to language.oop.constructor | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83924@lists.php.net to get a copy of this message | ||
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?
----
Manual Page -- http://www.php.net/manual/en/language.oop.constructor.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49358
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49358&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49358&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49358&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49358&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49358&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49358&report=yes
Search -- http://master.php.net/manage/user-notes.php