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([$this->rofl]); } public function unserialize($data) { list($this->rofl) = unserialize($data); } } class ParentB extends ParentA { public $collection; public function __construct(array $items) { $this->collection = []; foreach ($items as $item) { $this->collection[] = $item; } } public function serialize() { return serialize([ '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 = []; 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($data); 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/BEobu 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/BEobu on line 25 string(295) "O:7:"Wrapper":2:{s:6:"parent";C:7:"ParentB":198:{a:2:{s:3:"foo";a:3:{i:0;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:1;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:2;O:5:"Child":1:{s:8:"property";s:3:"foo";}}s:6:"parent";s:20:"a:1:{i:0;s:3:"foo";}";}}s:8:"children";a:3:{i:0;r:7;i:1;r:9;i:2;r:11;}}" Warning: unserialize(): Error at offset 293 of 295 bytes in /in/BEobu on line 78 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/BEobu 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/BEobu on line 25 string(295) "O:7:"Wrapper":2:{s:6:"parent";C:7:"ParentB":198:{a:2:{s:3:"foo";a:3:{i:0;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:1;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:2;O:5:"Child":1:{s:8:"property";s:3:"foo";}}s:6:"parent";s:20:"a:1:{i:0;s:3:"foo";}";}}s:8:"children";a:3:{i:0;r:7;i:1;r:9;i:2;r:11;}}" Notice: unserialize(): Error at offset 293 of 295 bytes in /in/BEobu on line 78 bool(false)
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
string(295) "O:7:"Wrapper":2:{s:6:"parent";C:7:"ParentB":198:{a:2:{s:3:"foo";a:3:{i:0;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:1;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:2;O:5:"Child":1:{s:8:"property";s:3:"foo";}}s:6:"parent";s:20:"a:1:{i:0;s:3:"foo";}";}}s:8:"children";a:3:{i:0;r:7;i:1;r:9;i:2;r:11;}}" Notice: unserialize(): Error at offset 293 of 295 bytes in /in/BEobu on line 78 bool(false)
Output for 7.3.32 - 7.3.33
string(295) "O:7:"Wrapper":2:{s:6:"parent";C:7:"ParentB":198:{a:2:{s:3:"foo";a:3:{i:0;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:1;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:2;O:5:"Child":1:{s:8:"property";s:3:"foo";}}s:6:"parent";s:20:"a:1:{i:0;s:3:"foo";}";}}s:8:"children";a:3:{i:0;r:7;i:1;r:9;i:2;r:11;}}" bool(false)
Output for 5.4.39 - 5.4.45, 5.5.23 - 5.5.38, 5.6.7 - 5.6.40, 7.0.6 - 7.0.33, 7.1.0 - 7.1.32, 7.2.0 - 7.2.33
string(295) "O:7:"Wrapper":2:{s:6:"parent";C:7:"ParentB":198:{a:2:{s:3:"foo";a:3:{i:0;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:1;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:2;O:5:"Child":1:{s:8:"property";s:3:"foo";}}s:6:"parent";s:20:"a:1:{i:0;s:3:"foo";}";}}s:8:"children";a:3:{i:0;r:7;i:1;r:9;i:2;r:11;}}" 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
string(295) "O:7:"Wrapper":2:{s:6:"parent";C:7:"ParentB":198:{a:2:{s:3:"foo";a:3:{i:0;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:1;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:2;O:5:"Child":1:{s:8:"property";s:3:"foo";}}s:6:"parent";s:20:"a:1:{i:0;s:3:"foo";}";}}s:8:"children";a:3:{i:0;r:7;i:1;r:9;i:2;r:11;}}" 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
string(295) "O:7:"Wrapper":2:{s:6:"parent";C:7:"ParentB":198:{a:2:{s:3:"foo";a:3:{i:0;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:1;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:2;O:5:"Child":1:{s:8:"property";s:3:"foo";}}s:6:"parent";s:20:"a:1:{i:0;s:3:"foo";}";}}s:8:"children";a:3:{i:0;r:7;i:1;r:9;i:2;r:11;}}" 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
string(295) "O:7:"Wrapper":2:{s:6:"parent";C:7:"ParentB":198:{a:2:{s:3:"foo";a:3:{i:0;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:1;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:2;O:5:"Child":1:{s:8:"property";s:3:"foo";}}s:6:"parent";s:20:"a:1:{i:0;s:3:"foo";}";}}s:8:"children";a:3:{i:0;r:7;i:1;r:9;i:2;r:11;}}" 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
string(295) "O:7:"Wrapper":2:{s:6:"parent";C:7:"ParentB":198:{a:2:{s:3:"foo";a:3:{i:0;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:1;O:5:"Child":1:{s:8:"property";s:3:"foo";}i:2;O:5:"Child":1:{s:8:"property";s:3:"foo";}}s:6:"parent";s:20:"a:1:{i:0;s:3:"foo";}";}}s:8:"children";a:3:{i:0;r:7;i:1;r:9;i:2;r:11;}}" 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" } }

preferences:
305.66 ms | 403 KiB | 366 Q