3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Acl implements \Serializable { private $id; private $objectIdentity; public function __construct($id, $objectIdentity) { $this->id = $id; $this->objectIdentity = $objectIdentity; } public function serialize() { return serialize([$this->id, $this->objectIdentity]); } public function unserialize($string) { list ($this->id, $this->objectIdentity) = unserialize($string); } } class Entry implements \Serializable { private $id; private $acl; private $sid; public function __construct($id, $acl, $sid) { $this->id = $id; $this->acl = $acl; $this->sid = $sid; } public function getSid() { return $this->sid; } public function serialize() { return serialize([$this->id, $this->sid]); } public function unserialize($string) { list ($this->id, $this->sid) = unserialize($string); } } class FieldEntry extends Entry implements \Serializable { private $field; public function __construct($id, $acl, $field, $sid) { parent::__construct($id, $acl, $sid); $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); } } final class Role { private $role; public function __construct($name) { $this->role = $name; } public function getRole() { return $this->role; } public function __toString() { return sprintf('RoleSecurityIdentity(%s)', $this->role); } } $acl = new Acl(1, null); $acl = new Acl(2, null); $sid = new Role('test'); $a = new FieldEntry(1, $acl, 'name', $sid, 'blabla'); $a1 = new FieldEntry(2, $acl, 'age', $sid, 'blabla'); $s = serialize( array( // Acl:serialize (line 260) [ // classFieldAces 'fieldOne' => [$a], 'fieldTwo' => [$a1], ] ) ); var_dump($s); $uns = unserialize($s); var_dump($uns[0]['fieldOne'][0]->getSid(), $uns[0]['fieldTwo'][0]->getSid());
based on pM0E2
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(Role)#6 (1) { ["role":"Role":private]=> string(4) "test" } 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(Role)#6 (1) { ["role":"Role":private]=> string(4) "test" } object(Role)#6 (1) { ["role":"Role":private]=> string(4) "test" }
Output for 5.4.2 - 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/sSL6F on line 16
Process exited with code 255.