3v4l.org

run code in 300+ PHP versions simultaneously
<?php class a implements \Serializable { /** @var b */ private $b; /** @var */ private $v; public function __construct($v, b $b) { $this->b = $b; $this->v = $v; } /** * {@inheritdoc} */ public function serialize() { return serialize([$this->v, $this->b]); } /** * {@inheritdoc} */ public function unserialize($serialized) { list($this->v, $this->b) = unserialize($serialized); } /** * @return b */ public function getB() { return $this->b; } } class b { private $b; public function __construct($b) { $this->b = $b; } } $b = new b('test'); $t = serialize([['field1' => new a(1, $b), 'field2' => new a(2, $b)]]); $t = serialize([1, $t]); list($sss, $uns) = unserialize($t); $uns = unserialize($uns); var_dump($uns); var_dump($uns[0]['field1']->getB() === $uns[0]['field2']->getB());
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: a 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/g3T71 on line 4 array(1) { [0]=> array(2) { ["field1"]=> object(a)#3 (2) { ["b":"a":private]=> object(b)#2 (1) { ["b":"b":private]=> string(4) "test" } ["v":"a":private]=> int(1) } ["field2"]=> object(a)#4 (2) { ["b":"a":private]=> object(b)#2 (1) { ["b":"b":private]=> string(4) "test" } ["v":"a":private]=> int(2) } } } bool(true)

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:
46.93 ms | 402 KiB | 8 Q