Re: Convert an array in an object instance

From: Date: Tue, 26 Oct 2004 07:11:52 +0000
Subject: Re: Convert an array in an object instance
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-13516@lists.php.net to get a copy of this message
Sorry, I've ask this question on general but no one seems to know if there's a solution for it. In fact, its possible to do something as: $MyObject = new MyClass (); $MyArray = (array) $MyObject; $MyObject2 = (object) $MyArray; But the original class of the object is lost -$MyObject2 appears as an instance of stdClass instead MyClass-. This wouldn't be a problem if there were a manner to tell PHP that $MyObject2 is a MyClass instance after the last line, but I didn't find a way to do that. In Perl there's a function that's called 'bless' that servers for this purpouse: http://www.emerson.emory.edu/services/perl/perldoc/manual/perlfunc/bless.html But I didn't found an equivalent in PHP. I'm writting my own serialization routines and I need this to unserialize objects. Thx. Derick Rethans wrote:
On Mon, 25 Oct 2004, Francisco M. Marzoa Alonso wrote:
Hi, Is it possible to convert an array in an object instance?
Please use the php-general@lists.php.net mailinglist for user support questions, this is the wrong list. Derick


« previous php.internals (#13516) next »