Re: Re: issues with __sleep() and __wakeup()
| From: | mike cullerton | Date: | Thu, 02 Aug 2001 05:41:51 +0000 |
| Subject: | Re: Re: issues with __sleep() and __wakeup() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-60835@lists.php.net to get a copy of this message | ||
cool. you and i were talking about two different things. you are using
__sleep and __wakeup by issuing the serialize and unserialize commands
yourself. i am using __sleep and __wakeup when php automatically issues
them itself when using sessions.
it is my experience that if you have an object and you register that object
as a session variable, and you do _not_ have a __sleep function, then
everything works fine. this is different from having a __sleep function and
not returning anything (or the wrong thing)
mike
on 8/1/01 9:32 AM, scott [gts] at scott@graphictype.com wrote:
> i added a (hopefully helpfull) addition to the
> online notes regarding magic-functions:
> http://www.php.net/manual/en/language.oop.magic-functions.php
>
> Here's what i posted, if anyone's interested:
>
> Here is a sample class and some test statements to
> demonstrate how __sleep() is used.
>
> If you do not return anything from __sleep(), your
> object will *not* be serialized. You must return
> something from __sleep() to tell serialize what
> to serialize.
>
> <?
> // to test the class
> $x = new Scott();
> print_r($x);
> $y = serialize($x);
> $z = unserialize($y);
> print_r($z);
>
> // Simple class to test __sleep()
> class Scott {
> // class variables
> var $error;
> var $svar = array();
>
> // constructor
> function Scott() {
> $this->svar['Hello'] = "World";
> }
>
> function __sleep() {
> $this->svar['Hello'] = "Yawn";
> // return list of instance-variables to be serialized
> return array('error', 'svar');
> }
>
> function __wakeup() {
> $this->svar['test'] = "I'm here!";
> }
>
> }// end class
> ?>
-- mike cullerton