I'm trying to unserialize
a saved instance state of an object but my serialized
object cannot be resumed due to an "error at offset" error.
This applies to all objects I try to unserialize, even the most simplest of objects.
class Object
{
protected $variable = true;
}
$object = serialize(new Object());
$string = 'O:6:"Object":1:{s:11:"*variable";b:1;}';
echo $object."\n";
echo "length: ". strlen($object)."\n\n";
echo $string . "\n"; // Strangely 2 characters shorter than $object
echo "length: ". strlen($string)."\n";
unserialize($object); // Works
unserialize($string); // Does not work
This code outputs:
O:6:"Object":1:{s:11:"*variable";b:1;}
length: 40
O:6:"Object":1:{s:11:"*variable";b:1;}
length: 38
Notice: unserialize(): Error at offset 33 of 38 bytes
I'm stuck, why can I not unserialize saved strings?