3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 = array(new Child(), new Child(), new Child()); $parent = new ParentB($children); $wrapper = new Wrapper($parent, $children); $data = serialize($wrapper); var_dump(unserialize($data));
Output for 5.4.39 - 5.6.28, 7.0.6 - 7.1.0
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.1.0 - 5.3.29, hhvm-3.12.0
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)#11 (1) { ["property"]=> string(3) "foo" } [1]=> object(Child)#12 (1) { ["property"]=> string(3) "foo" } [2]=> object(Child)#13 (1) { ["property"]=> string(3) "foo" } } }
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.4.20 - 5.4.38
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
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.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/ohFjs 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/ohFjs on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ohFjs 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/ohFjs on line 6
Process exited with code 255.