"Bless"ing an object
| From: | Wouter van Vliet | Date: | Tue, 25 Nov 2003 22:11:18 +0000 |
| Subject: | "Bless"ing an object | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-170949@lists.php.net to get a copy of this message | ||
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