casting user-defined objects

From: Date: Wed, 26 Jun 2002 20:43:27 +0000
Subject: casting user-defined objects
Groups: php.general 
Request: Send a blank email to php-general+get-104060@lists.php.net to get a copy of this message
I have been playing around and am unable to explicitly cast an object instance from one user-defined type to another, using the traditional type-casting syntax nor with the settype() function. I feel like I should mention this as an annotation in the man page, but I was hoping someone could steer me right if I'm wrong here. The following code doesn't work: class Apple { // some atts and meths function display() { // do something } } class Orange { // some atts and meths function display() { // do something } } // this part works fine $fruit = new Apple; $fruit->display(); // this part doesn't work like you think it would $newFruit = (Orange)$fruit; $newFruit->display(); The confusing thing is that this page http://www.php.net/manual/en/language.types.type-juggling.php actually does feature casting to objects, but I am unsure of what purpose the "object" type reference has. Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com

« previous php.general (#104060) next »