note 8487 modified in Classes and Objects by jmcastagnetto

From: Date: Thu, 14 Sep 2000 10:59:22 +0000
Subject: note 8487 modified in Classes and Objects by jmcastagnetto
Groups: php.notes 
Request: Send a blank email to php-notes+get-4972@lists.php.net to get a copy of this message
------------------------------------------------- [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. http://www.php.net/manual/classes-and-objects.php

« previous php.notes (#4972) next »