Re: Re: RE: [PHP-GENERAL] Re: [PHP-DEV] S essions and Objects
| From: | Andrei Zmievski | Date: | Mon, 19 Jun 2000 14:33:06 +0000 |
| Subject: | Re: Re: RE: [PHP-GENERAL] Re: [PHP-DEV] S essions and Objects | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-2197@lists.php.net to get a copy of this message | ||
On Mon, 19 Jun 2000, Millaway, John wrote:
> 1. References are lost during serialization. Example:
>
> class UserInfo {
> var $firstname, $fname;
>
> function UserInfo() {
> $fname = &$firstname; // Create reference
> }
> }
> The alias "fname" will not work correctly in the
> next page request.
Yes, that's true. I'm not quite sure how to deal with this situation.
>
> 2. Notification of session events. Ideally, an
> object which has been deserialized would be
> notified of this, either externally through
> a registered callback, or introspectively by
> calling an object's "onDeserialization()"
> method.
This is already done. If you define __wakeup() method, it will be called
when the object is deserialized.
> 3. Per-object serialization. PHP's introspection
> functionality is powerful enough to detect if an
> object has a "[de]serialize()" method, for example.
> If so, the object can provide it's own
> [de]serialization. It would be nice if the session
> handler could do this automatically.
One way of doing this is to define your own
serialization/deserialization functions that operate on a class member
variable. When session module is ready to serialize your object, it
will call __sleep() method on it. In that method you should serialize
your data to a string or whatever, and save it to a class member var
$foo, for example. Return array("foo") from __sleep(). That's it.
Upon deserialization, your __wakeup() method will get called. Then you
just deserialize your own data from $foo member variable.
-Andrei
What's hard, in hacking as in fiction,
is not the writing, it's deciding what to write.
-- Neal Stephenson