note 8487 deleted from language.oop by felipe

From: Date: Mon, 21 Jul 2008 01:16:41 +0000
Subject: note 8487 deleted from language.oop by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142382@lists.php.net to get a copy of this message
Note Submitter: simon dot li at hongkong dot com ---- ------------------------------------------------- [Editor's note: class casting per se is not part of the object/class implementation in PHP, but code like the one in this note can kludge if you need it for very simple cases, more complex ones are left to the imagination of the programmer: <?php class foo { function foo($name="foo") { $this->name=$name; } } class bar extends foo { function boom() { echo "BOOOM!"; } } $f = new foo(); $temp = explode(":",serialize($f)); $temp[2] = "\"bar\""; $b = unserialize(implode(":",$temp)); $b->boom(); ?> This forces $b to be an instance of "bar" using an object $f, an instance of "foo"] ------------------------------------------------- About casting of object, say, i got: class A extends B { function A() { $this->B(); } .... } $b = new B(); $a = new A(); I wanna have a object of class A with "content" of $b: $a = (A) $b; // not a valid code,(right?) as for illustration.

« previous php.notes (#142382) next »