3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo implements Serializable { public $obj; public function __construct( $obj ) { $this->obj = $obj; } public function serialize() { return serialize( array( 'obj' => $this->obj ) ); } public function unserialize( $s ) { $data = unserialize( $s ); $this->obj = $data['obj']; } } $obj = new stdclass; $foo1 = new Foo( $obj ); $foo2 = new Foo( $obj ); $s = serialize( array( $foo1, $foo2 ) ); var_dump( $s ); var_dump( unserialize( $s ) );
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Foo 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/J6g8e on line 3 string(99) "a:2:{i:0;C:3:"Foo":35:{a:1:{s:3:"obj";O:8:"stdClass":0:{}}}i:1;C:3:"Foo":20:{a:1:{s:3:"obj";r:4;}}}" array(2) { [0]=> object(Foo)#4 (1) { ["obj"]=> object(stdClass)#5 (0) { } } [1]=> object(Foo)#6 (1) { ["obj"]=> object(stdClass)#5 (0) { } } }
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: Foo 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/J6g8e on line 3 string(99) "a:2:{i:0;C:3:"Foo":35:{a:1:{s:3:"obj";O:8:"stdClass":0:{}}}i:1;C:3:"Foo":20:{a:1:{s:3:"obj";r:4;}}}" array(2) { [0]=> object(Foo)#4 (1) { ["obj"]=> object(stdClass)#5 (0) { } } [1]=> object(Foo)#6 (1) { ["obj"]=> object(stdClass)#5 (0) { } } }
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.6 - 7.0.32, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
string(99) "a:2:{i:0;C:3:"Foo":35:{a:1:{s:3:"obj";O:8:"stdClass":0:{}}}i:1;C:3:"Foo":20:{a:1:{s:3:"obj";r:4;}}}" array(2) { [0]=> object(Foo)#4 (1) { ["obj"]=> object(stdClass)#5 (0) { } } [1]=> object(Foo)#6 (1) { ["obj"]=> object(stdClass)#5 (0) { } } }
Output for 7.0.3 - 7.0.5
string(99) "a:2:{i:0;C:3:"Foo":35:{a:1:{s:3:"obj";O:8:"stdClass":0:{}}}i:1;C:3:"Foo":20:{a:1:{s:3:"obj";r:4;}}}" Notice: unserialize(): Error at offset 19 of 20 bytes in /in/J6g8e on line 15 array(2) { [0]=> object(Foo)#4 (1) { ["obj"]=> object(stdClass)#5 (0) { } } [1]=> object(Foo)#6 (1) { ["obj"]=> NULL } }
Output for 7.0.0 - 7.0.2
string(99) "a:2:{i:0;C:3:"Foo":35:{a:1:{s:3:"obj";O:8:"stdClass":0:{}}}i:1;C:3:"Foo":20:{a:1:{s:3:"obj";r:4;}}}" Notice: Undefined index: obj in /in/J6g8e on line 16 array(2) { [0]=> object(Foo)#4 (1) { ["obj"]=> object(stdClass)#5 (0) { } } [1]=> object(Foo)#6 (1) { ["obj"]=> NULL } }
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
string(114) "a:2:{i:0;C:3:"Foo":35:{a:1:{s:3:"obj";O:8:"stdClass":0:{}}}i:1;C:3:"Foo":35:{a:1:{s:3:"obj";O:8:"stdClass":0:{}}}}" array(2) { [0]=> object(Foo)#4 (1) { ["obj"]=> object(stdClass)#5 (0) { } } [1]=> object(Foo)#6 (1) { ["obj"]=> object(stdClass)#7 (0) { } } }
Output for 5.0.5
Fatal error: Interface 'Serializable' not found in /in/J6g8e on line 3
Process exited with code 255.
Output for 5.0.0 - 5.0.4
Fatal error: Class 'Serializable' not found in /in/J6g8e on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/J6g8e on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting '{' in /in/J6g8e on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'{'' in /in/J6g8e on line 3
Process exited with code 255.

preferences:
324.22 ms | 401 KiB | 444 Q