Re: Confused with constructors
| From: | Sebastian Mendel | Date: | Fri, 19 Nov 2004 10:57:23 +0000 |
| Subject: | Re: Confused with constructors | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-202499@lists.php.net to get a copy of this message | ||
Gerald Wharney wrote:
I'm trying the example at: http://www.php.net/manual/en/language.oop.constructor.php <?php class A { function A() {as i understand it exactly as you, it must be a bug/error -- Sebastian Mendel www.sebastianmendel.de www.warzonez.de www.tekkno4u.de www.nofetish.com www.sf.net/projects/phpdatetime www.sf.net/projects/phptimesheetecho "I am the constructor of A.<br />\n";} function B() {echo "I am a regular function named B in classA.<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; ?> Running this on 4.3.9 both as an apache module and from CLI I get: I am a regular function named B in class A. I am not a constructor in A. This is contrary to what the manual says: "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 />'." Is this an error in the manual? Or a bug in php 4.3.9? Or just me being stupid?