Voting

: six plus three?
(Example: nine)

The Note You're Voting On

Chris Hayes (chris at hypersites dot com)
20 years ago
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.

<< Back to user notes page

To Top