the php manual states:
It can clean up the object and is
supposed to return an array with the
names of all variables of that object
that should be serialized.
i understand this as, if a had a class. Like this:
<?php
class Foo {
public $bar = 'bar';
public $baz = 'baz';
public function __sleep() {
return array('bar');
}
}
$obj = new Foo();
$serialized = serialize($obj);
$unserialized = unserialize($serialized);
var_dump($unserialized);
?>
it would only serialize the object and the property $bar? Like this:
object(Foo)[2]
public 'bar' => string 'bar' (length=3)
but it returns:
object(Foo)[2]
public 'bar' => string 'bar' (length=3)
public 'baz' => string 'baz' (length=3)
Have i interpreted it wrong? Or am i doing it wrong or what?
Unserializing creates a new instance of the object, and since your definition of the class initializes the attribute, you’re getting a default value for it. Try this:
Edit: Alternatively, you can vardump($serialized) and see that there is no baz in it.