note 36828 deleted from function.serialize by aharvey
| From: | aharvey@php.net | Date: | Tue, 06 Nov 2012 02:03:08 +0000 |
| Subject: | note 36828 deleted from function.serialize by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191741@lists.php.net to get a copy of this message | ||
Note Submitter: ignatiev at users dot sourceforge dot net
----
One problem with serialize() is that by default it does NOT alter the object, so nothing prevents
you from continuing using you object after serialize()'ing it.
After a while, you or someone else decides to optimize storage of this object and add a __sleep and
__wakeup functions; now, serialize()'ing this same class calls __sleep() member function,
potentially changing the object - old code unexpectedly breaks.
Possible solutions: in the above scenario old code would most likely still work if __sleep() only
creates new object variables, not altering existing ones. Another option is to always call
__wakeup(), if it exists, after each serialize(), or immediately destroy the object if it is no
longer used.