Re: Re: Convert an array in an object instance

From: Date: Mon, 25 Oct 2004 13:57:04 +0000
Subject: Re: Re: Convert an array in an object instance
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-200251@lists.php.net to get a copy of this message
tularis@xmbforum.com 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.

« previous php.general (#200251) next »