note 46796 added to function.unserialize
| From: | (chris@hypersites.com) | Date: | Sat, 23 Oct 2004 16:27:58 +0000 |
| Subject: | note 46796 added to function.unserialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-79001@lists.php.net to get a copy of this message | ||
In reply to the earlier post about having to include object definitions *before* using unserialize.
There is a workaround for this.
When an object is serialized, the first bit of the string is actually the name of the class. When
an unknown object is unserialized, this is maintained as a property. So if you serialize it again,
you get back the exact same string as if you'd serialized the original object. Basically, to
cut to the point...
If you use
$_SESSION['my_object'] = unserialize(serialize($_SESSION['my_object']))
then you get back an object of the correct type, even if the session had originally loaded it as an
object of type stdClass.
----
Manual Page -- http://www.php.net/manual/en/function.unserialize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46796
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46796&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46796&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46796&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46796&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46796&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46796&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46796&report=yes
Search -- http://master.php.net/manage/user-notes.php