serializing anonymous objects
| From: | Chuck Hagenbuch | Date: | Sun, 02 Jul 2000 18:57:01 +0000 |
| Subject: | serializing anonymous objects | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-23240@lists.php.net to get a copy of this message | ||
The recent changes to the serializer/deserializer code have bitten me again.
Here's the scenario:
1. imap_rfc822_parse_adrlist() returns an array of objects.
2. I'd like to pass one or more of those to another script, and not have to
fetch them from the imap server or call the function again.
3. So I serialize them.
4. However, because of the new behavior, these are deserialized as stdClass,
and php errors out if I try to access any of the data in the object.
It's fine for this to be stdClass! I don't care if there are no method
definitions - there shouldn't be. I just want to be able to get at the data.
So, I see several options:
1. Convert imap_rfc822_parse_adrlist() to return an array of arrays. And all
of the other imap functions that use objects, etc. Problem: breaks
backwards compatibility completely.
2. I could step through the object and build an associative array, but
that's inelegant. Why bother doing the work?
3. Have a special type (internalClass?) for objects created by php that are
allowed to just have data, and can be serialized/deserialized with no
definitions around. No particular problems with this, but...
4. ... making the serializer smart enough to recognize objects that are
stdClass before the first time they're serialized, and just leaving them
alone, seems much more elegant.
-chuck
--
Charles Hagenbuch, <chagenbu@wso.williams.edu>
--
"hello, I'm a giant cheese, and I'm here to give you a therapeutic massage"