3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Entry implements \Serializable { protected $id; protected $role; public function __construct($id, $role) { $this->id = $id; $this->role = $role; } public function serialize() { return serialize([$this->id, $this->role]); } public function unserialize($string) { list ($this->id, $this->role) = unserialize($string); } } class FieldEntry extends Entry implements \Serializable { protected $field; public function __construct($id, $role, $field) { parent::__construct($id, $role); $this->field = $field; } public function serialize() { return serialize([$this->field, parent::serialize()]); } public function unserialize($string) { list($this->field, $parentStr) = unserialize($string); parent::unserialize($parentStr); } } class Role { private $role; public function __construct($name) { $this->role = $name; } } $b = new Role('test'); $a = new FieldEntry(1, $b, 'name'); $a1 = new FieldEntry(2, $b, 'age'); $s = serialize( array( // Acl:serialize (line 260) [ // classFieldAces 'fieldOne' => [$a], 'fieldTwo' => [$a1], ] ) ); var_dump($s); $uns = unserialize($s); var_dump($uns[0]['fieldOne'][0], $uns[0]['fieldTwo'][0]);
Output for 5.4.39 - 5.6.28, 7.0.6 - 7.2.0
string(261) "a:1:{i:0;a:2:{s:8:"fieldOne";a:1:{i:0;C:10:"FieldEntry":95:{a:2:{i:0;s:4:"name";i:1;s:62:"a:2:{i:0;i:1;i:1;O:4:"Role":1:{s:10:"Rolerole";s:4:"test";}}";}}}s:8:"fieldTwo";a:1:{i:0;C:10:"FieldEntry":54:{a:2:{i:0;s:3:"age";i:1;s:22:"a:2:{i:0;i:2;i:1;r:7;}";}}}}}" object(FieldEntry)#4 (3) { ["field":protected]=> string(4) "name" ["id":protected]=> int(1) ["role":protected]=> object(Role)#5 (1) { ["role":"Role":private]=> string(4) "test" } } object(FieldEntry)#6 (3) { ["field":protected]=> string(3) "age" ["id":protected]=> int(2) ["role":protected]=> string(62) "a:2:{i:0;i:1;i:1;O:4:"Role":1:{s:10:"Rolerole";s:4:"test";}}" }
Output for 7.0.0 - 7.0.5
string(261) "a:1:{i:0;a:2:{s:8:"fieldOne";a:1:{i:0;C:10:"FieldEntry":95:{a:2:{i:0;s:4:"name";i:1;s:62:"a:2:{i:0;i:1;i:1;O:4:"Role":1:{s:10:"Rolerole";s:4:"test";}}";}}}s:8:"fieldTwo";a:1:{i:0;C:10:"FieldEntry":54:{a:2:{i:0;s:3:"age";i:1;s:22:"a:2:{i:0;i:2;i:1;r:7;}";}}}}}" object(FieldEntry)#4 (3) { ["field":protected]=> string(4) "name" ["id":protected]=> int(1) ["role":protected]=> object(Role)#5 (1) { ["role":"Role":private]=> string(4) "test" } } object(FieldEntry)#6 (3) { ["field":protected]=> string(3) "age" ["id":protected]=> int(2) ["role":protected]=> object(Role)#5 (1) { ["role":"Role":private]=> string(4) "test" } }
Output for 5.4.1 - 5.4.38
string(261) "a:1:{i:0;a:2:{s:8:"fieldOne";a:1:{i:0;C:10:"FieldEntry":95:{a:2:{i:0;s:4:"name";i:1;s:62:"a:2:{i:0;i:1;i:1;O:4:"Role":1:{s:10:"Rolerole";s:4:"test";}}";}}}s:8:"fieldTwo";a:1:{i:0;C:10:"FieldEntry":54:{a:2:{i:0;s:3:"age";i:1;s:22:"a:2:{i:0;i:2;i:1;r:7;}";}}}}}"
Process exited with code 139.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/pM0E2 on line 16
Process exited with code 255.