@ 2017-06-01T09:41:01Z <?php
class Foo
{
public function __sleep()
{
return [];
}
public function __wakeup()
{
echo 'Called ' . __METHOD__ . PHP_EOL;
}
}
class Bar implements \Serializable
{
private $foo;
public function __construct(Foo $foo)
{
$this->foo = $foo;
}
public function serialize()
{
return serialize($this->foo);
}
public function unserialize($serialized)
{
echo 'unserialize Foo' . PHP_EOL;
$this->foo = unserialize($serialized);
echo 'end unserialize Foo' . PHP_EOL;
}
}
$foo = new Foo();
$bar = new Bar($foo);
$barStr = serialize($bar);
$newBar = unserialize($barStr);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.1.0 - 8.1.33 , 8.2.0 - 8.2.29 , 8.3.0 - 8.3.25 , 8.4.1 - 8.4.12 Deprecated: Bar implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /in/MlbuO on line 15
unserialize Foo
end unserialize Foo
Called Foo::__wakeup
Output for 5.6.30 - 5.6.40 , 7.0.15 - 7.0.33 , 7.1.1 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 unserialize Foo
end unserialize Foo
Called Foo::__wakeup
Output for 5.6.0 - 5.6.29 , 7.0.0 - 7.0.14 , 7.1.0 unserialize Foo
Called Foo::__wakeup
end unserialize Foo
preferences:dark mode live preview ace vim emacs key bindings
145.37 ms | 409 KiB | 5 Q