note 76628 deleted from language.oop5.magic by bjori
| From: | bjori@php.net | Date: | Tue, 24 Jul 2007 11:11:16 +0000 |
| Subject: | note 76628 deleted from language.oop5.magic by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-128866@lists.php.net to get a copy of this message | ||
Note Submitter: amir dot abiri at ipcmedia dot com
----
There is a little quirk with __wakeup() and initializer values of member variables.
The following code will not quite work as expected:
class A
{
public $a = 1;
function __sleep()
{
return array();
}
function __wakeup()
{
$this->a = 2;
}
}
print_r(unserialize(serialize(new A)));
result:
A Object
(
[a] => 1
)
The reason for this is that when the object is unserialized, the constructor isn't called, but
initializers of member variables are applied (probably not on purpose, simply the default behaviour
of creating an object). Then __wakeup() is called.