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.
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:
my $SomeInstance = bless { item => 'value', 'Item2' => 'value2' }, 'SomeObject';
And then if I decide that $SomeInstance should be an intance of some other object:
bless $SomeInstance, 'OtherObject';
In PHP it would be extremely useful for for doing something like this:
<?php Class Foo { Load() { ( .. ) }
};
Class Bar extends Foo {
}
$Thing = new Foo(); $Thing->Load(); ?>
In Load the object data is loaded from the database, and now imagine one row to contain the subclass this instance of Foo should become. I then would want $Thing to become and thus behave like an instance of Bar (if my database row says so).
Hope this message wasn't too confusing ;) Wouter
-- Raditha Dissanayake. ------------------------------------------------------------------------ http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader Graphical User Inteface. Just 150 KB | with progress bar.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php