3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { public $y = 'b'; public $foo; public $bar; public $x = "A"; } class B { public $baz; function __wakeup() { echo "Within wakeup\n"; var_dump($this->baz); echo "Done wakeup\n"; } } $a = new A(); $b = new B(); $a->foo = $b; $a->bar = "something"; $b->baz = $a; var_dump($a); $unserialized = unserialize(serialize([$a])); echo "After unserialize\n"; var_dump($unserialized);
Output for 7.0.20, 7.1.5 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
object(A)#1 (4) { ["y"]=> string(1) "b" ["foo"]=> object(B)#2 (1) { ["baz"]=> *RECURSION* } ["bar"]=> string(9) "something" ["x"]=> string(1) "A" } Within wakeup object(A)#3 (4) { ["y"]=> string(1) "b" ["foo"]=> object(B)#4 (1) { ["baz"]=> *RECURSION* } ["bar"]=> string(9) "something" ["x"]=> string(1) "A" } Done wakeup After unserialize array(1) { [0]=> object(A)#3 (4) { ["y"]=> string(1) "b" ["foo"]=> object(B)#4 (1) { ["baz"]=> *RECURSION* } ["bar"]=> string(9) "something" ["x"]=> string(1) "A" } }
Output for 7.0.0 - 7.0.9, 7.1.0
object(A)#1 (4) { ["y"]=> string(1) "b" ["foo"]=> object(B)#2 (1) { ["baz"]=> *RECURSION* } ["bar"]=> string(9) "something" ["x"]=> string(1) "A" } Within wakeup object(A)#3 (4) { ["y"]=> string(1) "b" ["foo"]=> object(B)#4 (1) { ["baz"]=> *RECURSION* } ["bar"]=> NULL ["x"]=> string(1) "A" } Done wakeup After unserialize array(1) { [0]=> object(A)#3 (4) { ["y"]=> string(1) "b" ["foo"]=> object(B)#4 (1) { ["baz"]=> *RECURSION* } ["bar"]=> string(9) "something" ["x"]=> string(1) "A" } }
Output for 5.6.9 - 5.6.23
object(A)#1 (4) { ["y"]=> string(1) "b" ["foo"]=> object(B)#2 (1) { ["baz"]=> *RECURSION* } ["bar"]=> string(9) "something" ["x"]=> string(1) "A" } Within wakeup object(A)#3 (4) { ["y"]=> string(1) "b" ["foo"]=> NULL ["bar"]=> NULL ["x"]=> string(1) "A" } Done wakeup After unserialize array(1) { [0]=> object(A)#3 (4) { ["y"]=> string(1) "b" ["foo"]=> object(B)#4 (1) { ["baz"]=> *RECURSION* } ["bar"]=> string(9) "something" ["x"]=> string(1) "A" } }

preferences:
140.86 ms | 411 KiB | 5 Q