3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Foo { public $foo = 'foo'; protected $bar = 'two'; private $baz = 'three'; } $a = new Foo(); $b = (array)$a; var_dump($a); var_dump($b); foreach ($b as $key => $val) { var_dump($key); var_dump($val); print "\n"; }
Output for 5.3.0 - 5.6.21, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
object(Foo)#1 (3) { ["foo"]=> string(3) "foo" ["bar":protected]=> string(3) "two" ["baz":"Foo":private]=> string(5) "three" } array(3) { ["foo"]=> string(3) "foo" ["*bar"]=> string(3) "two" ["Foobaz"]=> string(5) "three" } string(3) "foo" string(3) "foo" string(6) "*bar" string(3) "two" string(8) "Foobaz" string(5) "three"
Output for 5.0.0 - 5.2.17
object(Foo)#1 (3) { ["foo"]=> string(3) "foo" ["bar:protected"]=> string(3) "two" ["baz:private"]=> string(5) "three" } array(3) { ["foo"]=> string(3) "foo" ["*bar"]=> string(3) "two" ["Foobaz"]=> string(5) "three" } string(3) "foo" string(3) "foo" string(6) "*bar" string(3) "two" string(8) "Foobaz" string(5) "three"
Output for 4.4.2 - 4.4.9
<br /> <b>Parse error</b>: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/in/XADPT</b> on line <b>4</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
<br /> <b>Parse error</b>: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/in/XADPT</b> on line <b>4</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in <b>/in/XADPT</b> on line <b>4</b><br />
Process exited with code 255.