note 76628 added to language.oop5.magic

From: Date: Mon, 23 Jul 2007 17:40:21 +0000
Subject: note 76628 added to language.oop5.magic
Groups: php.notes 
Request: Send a blank email to php-notes+get-128847@lists.php.net to get a copy of this message
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. ---- Server IP: 64.71.164.2 Probable Submitter: 64.236.80.62 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.magic.php Edit -- https://master.php.net/note/edit/76628 Del: integrated -- https://master.php.net/note/delete/76628/integrated Del: useless -- https://master.php.net/note/delete/76628/useless Del: bad code -- https://master.php.net/note/delete/76628/bad+code Del: spam -- https://master.php.net/note/delete/76628/spam Del: non-english -- https://master.php.net/note/delete/76628/non-english Del: in docs -- https://master.php.net/note/delete/76628/in+docs Del: other reasons-- https://master.php.net/note/delete/76628 Reject -- https://master.php.net/note/reject/76628 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128847) next »