3v4l.org

run code in 300+ PHP versions simultaneously
<?php // 'Child' object. class Child { public $property = 'foo'; } // 'Parent' object. class ParentA implements Serializable { public $rofl = 'foo'; public function serialize() { return serialize(array($this->rofl)); } public function unserialize($data) { list($this->rofl) = unserialize($data); } } class ParentB extends ParentA { public $collection; public function __construct(array $items) { $this->collection = array(); foreach ($items as $item) { $this->collection[] = $item; } } public function serialize() { return serialize(array( 'foo' => $this->collection, 'parent' => parent::serialize() )); } public function unserialize($data) { $data = unserialize($data); $this->collection = $data['foo']; parent::unserialize($data['parent']); } } // Wrapper object. class Wrapper { public $parent; public $children; public function __construct(ParentB $parent, array $children) { $this->parent = $parent; $this->children = array(); foreach ($children as $child) { $this->children[] = $child; } } } $children = [new Child(), new Child(), new Child()]; $parent = new ParentB($children); $wrapper = new Wrapper($parent, $children); $data = serialize($wrapper); var_dump(unserialize($data));
Output for 8.3.0 - 8.3.6
Deprecated: ParentA 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/glXW9 on line 10 Deprecated: ParentB 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/glXW9 on line 25 Warning: unserialize(): Error at offset 293 of 295 bytes in /in/glXW9 on line 77 bool(false)
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Deprecated: ParentA 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/glXW9 on line 10 Deprecated: ParentB 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/glXW9 on line 25 Notice: unserialize(): Error at offset 293 of 295 bytes in /in/glXW9 on line 77 bool(false)
Output for 7.3.12 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Notice: unserialize(): Error at offset 293 of 295 bytes in /in/glXW9 on line 77 bool(false)
Output for 7.3.32 - 7.3.33
bool(false)
Output for 5.4.39 - 5.4.45, 5.5.23 - 5.5.36, 5.6.7 - 5.6.28, 7.0.6 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33
object(Wrapper)#6 (2) { ["parent"]=> object(ParentB)#7 (2) { ["collection"]=> array(3) { [0]=> object(Child)#8 (1) { ["property"]=> string(3) "foo" } [1]=> object(Child)#9 (1) { ["property"]=> string(3) "foo" } [2]=> object(Child)#10 (1) { ["property"]=> string(3) "foo" } } ["rofl"]=> string(3) "foo" } ["children"]=> array(3) { [0]=> object(Child)#9 (1) { ["property"]=> string(3) "foo" } [1]=> object(Child)#10 (1) { ["property"]=> string(3) "foo" } [2]=> string(20) "a:1:{i:0;s:3:"foo";}" } }
Output for 7.0.0 - 7.0.5
object(Wrapper)#6 (2) { ["parent"]=> object(ParentB)#7 (2) { ["collection"]=> array(3) { [0]=> object(Child)#8 (1) { ["property"]=> string(3) "foo" } [1]=> object(Child)#9 (1) { ["property"]=> string(3) "foo" } [2]=> object(Child)#10 (1) { ["property"]=> string(3) "foo" } } ["rofl"]=> string(3) "foo" } ["children"]=> array(3) { [0]=> object(Child)#9 (1) { ["property"]=> string(3) "foo" } [1]=> object(Child)#10 (1) { ["property"]=> string(3) "foo" } [2]=> object(Child)#10 (1) { ["property"]=> string(3) "foo" } } }
Output for 5.4.20 - 5.4.38, 5.5.4 - 5.5.22, 5.6.0 - 5.6.6
object(Wrapper)#6 (2) { ["parent"]=> object(ParentB)#7 (2) { ["collection"]=> array(3) { [0]=> object(Child)#8 (1) { ["property"]=> string(3) "foo" } [1]=> object(Child)#9 (1) { ["property"]=> string(3) "foo" } [2]=> object(Child)#10 (1) { ["property"]=> string(3) "foo" } } ["rofl"]=> string(3) "foo" } ["children"]=> array(3) { [0]=> object(Child)#9 (1) { ["property"]=> string(3) "foo" } [1]=> object(Child)#10 (1) { ["property"]=> string(3) "foo" } [2]=> NULL } }
Output for 5.4.7 - 5.4.19, 5.5.0 - 5.5.3
object(Wrapper)#6 (2) { ["parent"]=> object(ParentB)#7 (2) { ["collection"]=> array(3) { [0]=> object(Child)#8 (1) { ["property"]=> string(3) "foo" } [1]=> object(Child)#9 (1) { ["property"]=> string(3) "foo" } [2]=> object(Child)#10 (1) { ["property"]=> string(3) "foo" } } ["rofl"]=> string(3) "foo" } ["children"]=> array(3) { [0]=> object(Child)#9 (1) { ["property"]=> string(3) "foo" } [1]=> object(Child)#10 (1) { ["property"]=> string(3) "foo" } [2]=> string(20) "1Y" } }
Process exited with code 255.
Output for 5.4.0 - 5.4.6
object(Wrapper)#6 (2) { ["parent"]=> object(ParentB)#7 (2) { ["collection"]=> array(3) { [0]=> object(Child)#8 (1) { ["property"]=> string(3) "foo" } [1]=> object(Child)#9 (1) { ["property"]=> string(3) "foo" } [2]=> object(Child)#10 (1) { ["property"]=> string(3) "foo" } } ["rofl"]=> string(3) "foo" } ["children"]=> array(3) { [0]=> object(Child)#9 (1) { ["property"]=> string(3) "foo" } [1]=> object(Child)#10 (1) { ["property"]=> string(3) "foo" } [2]=> string(20) "1Y" } }
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/glXW9 on line 72
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/glXW9 on line 29
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/glXW9 on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/glXW9 on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/glXW9 on line 6
Process exited with code 255.

preferences:
243.38 ms | 401 KiB | 348 Q