3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Foo { protected $bars = []; public function addBar(Bar $bar) { $this->bars[] = $bar; } } class Bar { protected $value; public function __construct($value) { $this->value = $value; } } $foo = new Foo; $foo->addBar(new Bar('baz')); $foo->addBar(new Bar(42)); $foo = serialize($foo); echo $foo, PHP_EOL; $foo = unserialize($foo); var_dump($foo);
Output for 5.4.0 - 5.6.28, 7.0.0 - 7.1.0
O:3:"Foo":1:{s:7:"*bars";a:2:{i:0;O:3:"Bar":1:{s:8:"*value";s:3:"baz";}i:1;O:3:"Bar":1:{s:8:"*value";i:42;}}} object(Foo)#1 (1) { ["bars":protected]=> array(2) { [0]=> object(Bar)#3 (1) { ["value":protected]=> string(3) "baz" } [1]=> object(Bar)#2 (1) { ["value":protected]=> int(42) } } }
Output for hhvm-3.10.0 - 3.13.2
O:3:"Foo":1:{s:7:"*bars";a:2:{i:0;O:3:"Bar":1:{s:8:"*value";s:3:"baz";}i:1;O:3:"Bar":1:{s:8:"*value";i:42;}}} object(Foo)#3 (1) { ["bars":protected]=> array(2) { [0]=> object(Bar)#4 (1) { ["value":protected]=> string(3) "baz" } [1]=> object(Bar)#5 (1) { ["value":protected]=> int(42) } } }
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/VtXgD on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/VtXgD on line 5
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/VtXgD on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/VtXgD on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/VtXgD on line 5
Process exited with code 255.