issues with __sleep() and __wakeup()
| From: | scott [gts] | Date: | Tue, 31 Jul 2001 19:48:18 +0000 |
| Subject: | issues with __sleep() and __wakeup() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-60494@lists.php.net to get a copy of this message | ||
I am having a problem with __sleep();
there mere existance of it is causing my object
to not get serialized at all. __wakeup() works fine.
i am using PHP v4.0.6 / apache / win2k.
If i keep __sleep() in the object, it will not serialize,
but if i remove it, it serialized fine. Does anyone
know why this happens?
Here's my object:
class Scott {
var $svar = array(); // free-form hash for whatever data
function Scott( )
{
return $this;
}
function __sleep()
{
}
function __wakeup()
{
$this->svar['sleep'] = "I am waking up";
}
}// end class
and now a test script
require_once('class.Scott.php');
$scott = new Scott();
$scott->svar['blah'] = "bacon";
print "object = ". $scott ."\n";
print "blah = ". $scott->svar['blah'] ."\n";
print "\n";
// serialize
$ser = serialize($scott);
print "serialized = ". $ser ."\n";
// trash the object
unset($scott);
print "unset object = ". $scott ."\n\n";
// unserialize
$scott = unserialize($ser);
print "object = ". $scott ."\n";
print "blah = ". $scott->svar['blah'] ."\n";
print "sleep = ". $scott->svar['sleep'] ."\n";