RE: [PHP] "Bless"ing an object

From: Date: Wed, 26 Nov 2003 10:19:22 +0000
Subject: RE: [PHP] "Bless"ing an object
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-171015@lists.php.net to get a copy of this message
Raditha Dissanayake wrote: > Hi Wouter, > > Wouter van Vliet wrote: > >> Hi Folks >> >> I was wondering (mostly because I came across some situations where >> I need it) if PHP supplies any methods to "bless" an array or object >> to become some other object. In perl, I can simply do: (..) >> > > I suspect that the reason that you find bless in perl is > because it's OO foundations are not as strong as even that of > PHP. Well PHP's OO foundations are weak enough. :-) > > The specific scenario you have described can IMHO be achieved > with the use of serialize / deserialize. Hmm, seriailze and deserialize.. Don't think that's what I would want to do. You probably mean that I can serialize an object, hack the string to change the Class reference. That's not really what I want to do. Right now I'm hacking through it by *) Creating a new instance of the desired class ($New = new OtherClass()) *) Copy all attributes (foreach($this as $Key=>$Value) $New[$Key] = $Value) *) Replace the "$this" var ($this = $New) Not the best solution, I now .. But it works, currently. Please, there must be another way to do this ! Wouter

« previous php.general (#171015) next »