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([ '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 git.master, git.master_jit
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/pDLcI 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/pDLcI on line 25 Notice: unserialize(): Error at offset 293 of 295 bytes in /in/pDLcI on line 77 bool(false)
Output for rfc.property-hooks
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/pDLcI 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/pDLcI on line 25 Warning: unserialize(): Error at offset 293 of 295 bytes in /in/pDLcI on line 77 bool(false)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
33.09 ms | 402 KiB | 8 Q