Marek Kilimajer wrote:
Francisco M. Marzoa Alonso wrote:
tularis@xxxxxxxxxxxx wrote:
No. You need to remember that in most cases where you cast a variable from
one type to another, you will experience data (precision) loss. This is
also the case in converting an object to an array. Only the properties are
copied over (since functions can not be part of an array).
The point is interesting, but as far as I do not need to store class methods I think there's nothing lost between conversion. I'll store the name of the class of the instance, so the methods of the instance will be those of that class. I only need some manner to tell PHP that the object is an instance of "MyClass" (following the original example) to have the object exactly equal as it was before conversions.
Perl has a function to to that, that's called bless: http://www.perldoc.com/perl5.6/pod/func/bless.html
FYI, the reason I need this is because I'm creating my own object's serialization routines.
$obj = new MyClass; foreach($array as $key => $val) $obj->$key = $val;
Not very elegant but the only way as far as I know
Its an interesting workaround, but that doesn't work with classes that has mandatory arguments on its constructors. :-(
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php