note 21241 added to language.oop.constructor

From: Date: Sat, 04 May 2002 17:59:28 +0000
Subject: note 21241 added to language.oop.constructor
Groups: php.notes 
Request: Send a blank email to php-notes+get-30188@lists.php.net to get a copy of this message
This works in PHP 4.1.2 and probably versions > 4.x. Creating an object from a constructor of a different class type can be accomplished. Note that you can NOT return an object from a constructor. A constructor can never return a value. However, you can set the value of $this to acheive this. For example: <? class A { function A() { $this = new B(); } } class B { function iamab() { echo "i am an object of class B"; } } $a = new A(); echo '$a is a ' . get_class($a) . "\n"; $a->iamab() ?> would print out: $a is a b i am an object of class B -- http://www.php.net/manual/en/language.oop.constructor.php http://master.php.net/manage/user-notes.php?action=edit+21241 http://master.php.net/manage/user-notes.php?action=delete+21241 http://master.php.net/manage/user-notes.php?action=reject+21241

« previous php.notes (#30188) next »