note 34218 deleted from function.serialize by aharvey
| From: | aharvey@php.net | Date: | Tue, 06 Nov 2012 02:02:40 +0000 |
| Subject: | note 34218 deleted from function.serialize by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191738@lists.php.net to get a copy of this message | ||
Note Submitter: dan at mojavelinux dot com
----
In order to safely unserialize a complex object in any context, it is wise to save two files at the
time of serialization (or save the file in two parts). One file will contain the result of
get_included_files() at the time of serialization and the other file contains the serialized version
of the object. To unserialize, simply read in the included file list and call include_once on all
of those files and then call unserialize on your object data.
While this may be slightly inefficient because certain files that were included are no longer needed
(maybe they were only needed when creating the object), at least you can be sure the object data is
going to come out of serialization okay.
Note: If you stick to the convention of classes beginning with uppercase (and the filenames
following the classnames) then you can even filter the get_included_files() list to get only the
class definition files.