3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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 5.4.2 - 5.6.28, 7.0.6 - 7.2.0
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)
Output for 7.0.3 - 7.0.5
Notice: unserialize(): Error at offset 21 of 22 bytes in /in/g3T71 on line 29 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]=> NULL ["v":"a":private]=> NULL } } } bool(false)
Output for 7.0.0 - 7.0.2
Notice: Undefined offset: 1 in /in/g3T71 on line 29 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]=> NULL ["v":"a":private]=> int(2) } } } bool(false)
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/g3T71 on line 21
Process exited with code 255.