note 17514 deleted from language.oop.constructor by danbrown

From: Date: Sat, 07 Nov 2009 18:58:29 +0000
Subject: note 17514 deleted from language.oop.constructor by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162543@lists.php.net to get a copy of this message
Note Submitter: ---- A couple of comments : <<If a class has no constructor, the constructor of the base class is being called, if it exists.>> Actually the constructor of the base class is NOT called. The child class inherits TWO copies of the father constructor, one named after the father, one named after the child. (other methods are also inherited by copy, as stated in the manual!) The copied method named after the child is being called. For most purposes this is the same, but beware of static variables. class bar{ function bar($var = null){ static $methodname = "bar::bar"; if(isset($var)) $methodname = $var; else echo "$methodname <b"."r>"; } } class foo extends bar{ function printMethods(){ bar::bar(); foo::bar(); foo::foo(); } } foo::printMethods(); // prints 3 bar::bar foo::foo('foo::foo'); foo::bar('foo::bar'); foo::printMethods(); // prints bar::bar,foo::bar,foo::foo $foo = new foo; // prints foo::foo $bar = new bar; // prints bar::bar Ivan

« previous php.notes (#162543) next »