3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php error_reporting(E_ALL|E_STRICT); class Obj { // Testing $this->a being a dynamic property. public function __construct($a) { $this->a = $a; } public function __wakeup() { for ($i = 0; $i < 10000; $i++) { $this->{'b' . $i} = 42; } } } function main() { $obj = (object)["test" => 'foo']; // object used twice as properties of other objects. $variable = [new Obj($obj), new Obj($obj)]; $serialized = serialize($variable); printf("%s\n", $serialized); $unserialized = unserialize($serialized); echo "Called __unserialize\n"; for ($a = 0; $a < 2; $a++) { for ($i = 0; $i < 10000; $i++) { if ($unserialized[$a]->{'b' . $i} !== 42) { echo "Fail $a b$i\n"; return; } unset($unserialized[$a]->{'b' . $i}); } } var_dump($unserialized); } main();
based on 1SsOJ
Output for 5.6.0 - 5.6.23, 7.0.20, 7.1.5 - 7.3.1
a:2:{i:0;O:3:"Obj":1:{s:1:"a";O:8:"stdClass":1:{s:4:"test";s:3:"foo";}}i:1;O:3:"Obj":1:{s:1:"a";r:3;}} Called __unserialize array(2) { [0]=> object(Obj)#4 (1) { ["a"]=> object(stdClass)#5 (1) { ["test"]=> string(3) "foo" } } [1]=> object(Obj)#6 (1) { ["a"]=> object(stdClass)#5 (1) { ["test"]=> string(3) "foo" } } }
Output for 7.0.3 - 7.0.8, 7.1.0
a:2:{i:0;O:3:"Obj":1:{s:1:"a";O:8:"stdClass":1:{s:4:"test";s:3:"foo";}}i:1;O:3:"Obj":1:{s:1:"a";r:3;}} Notice: unserialize(): Error at offset 100 of 102 bytes in /in/DkcB5 on line 20 Called __unserialize Notice: Trying to get property of non-object in /in/DkcB5 on line 24 Fail 0 b0
Output for 7.0.0 - 7.0.2
a:2:{i:0;O:3:"Obj":1:{s:1:"a";O:8:"stdClass":1:{s:4:"test";s:3:"foo";}}i:1;O:3:"Obj":1:{s:1:"a";r:3;}} Called __unserialize array(2) { [0]=> object(Obj)#4 (1) { ["a"]=> object(stdClass)#5 (1) { ["test"]=> string(3) "foo" } } [1]=> object(Obj)#6 (0) { } }