3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
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.21, 7.4.0 - 7.4.9, 8.0.0alpha1 - beta1
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