3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.3.0 - 8.3.4, 8.3.6
Deprecated: Entry 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/pM0E2 on line 3 Deprecated: FieldEntry 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/pM0E2 on line 25 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;}";}}}}}" Warning: unserialize(): Error at offset 21 of 22 bytes in /in/pM0E2 on line 21 object(FieldEntry)#4 (3) { ["id":protected]=> int(1) ["role":protected]=> object(Role)#5 (1) { ["role":"Role":private]=> string(4) "test" } ["field":protected]=> string(4) "name" } object(FieldEntry)#6 (3) { ["id":protected]=> NULL ["role":protected]=> NULL ["field":protected]=> string(3) "age" }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Deprecated: Entry 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/pM0E2 on line 3 Deprecated: FieldEntry 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/pM0E2 on line 25 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;}";}}}}}" Warning: unserialize(): Error at offset 21 of 22 bytes in /in/pM0E2 on line 21 object(FieldEntry)#4 (3) { ["id":protected]=> int(1) ["role":protected]=> object(Role)#5 (1) { ["role":"Role":private]=> string(4) "test" } ["field":protected]=> string(4) "name" } object(FieldEntry)#6 (3) { ["id":protected]=> NULL ["role":protected]=> NULL ["field":protected]=> string(3) "age" }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
Deprecated: Entry 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/pM0E2 on line 3 Deprecated: FieldEntry 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/pM0E2 on line 25 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;}";}}}}}" Notice: unserialize(): Error at offset 21 of 22 bytes in /in/pM0E2 on line 21 object(FieldEntry)#4 (3) { ["id":protected]=> int(1) ["role":protected]=> object(Role)#5 (1) { ["role":"Role":private]=> string(4) "test" } ["field":protected]=> string(4) "name" } object(FieldEntry)#6 (3) { ["id":protected]=> NULL ["role":protected]=> NULL ["field":protected]=> string(3) "age" }
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
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;}";}}}}}" Notice: unserialize(): Error at offset 21 of 22 bytes in /in/pM0E2 on line 21 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]=> NULL ["role":protected]=> NULL }
Output for 7.3.32 - 7.3.33
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]=> NULL ["role":protected]=> NULL }
Output for 5.4.39 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.6 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
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.

preferences:
182.17 ms | 401 KiB | 257 Q