note 17514 added to language.oop.constructor

From: Date: Wed, 12 Dec 2001 16:38:00 +0000
Subject: note 17514 added to language.oop.constructor
Groups: php.notes 
Request: Send a blank email to php-notes+get-22543@lists.php.net to get a copy of this message
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 -- http://www.php.net/manual/en/language.oop.constructor.php http://master.php.net/manage/user-notes.php?action=edit+17514 http://master.php.net/manage/user-notes.php?action=delete+17514 http://master.php.net/manage/user-notes.php?action=reject+17514

« previous php.notes (#22543) next »