3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { private $a = 0; protected $b = true; public $c = 'hello'; } class Another extends Test { private $a = 1; protected $b = false; public $d ='wow'; } $obj = new Another(); $data = (array) $obj; $new = (object) $data; echo $new->c, $new->d, $new->b, $new->a; var_dump($data); var_dump($new);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
hellowow Warning: Undefined property: stdClass::$b in /in/aFbJW on line 25 Warning: Undefined property: stdClass::$a in /in/aFbJW on line 25 array(5) { ["Testa"]=> int(0) ["*b"]=> bool(false) ["c"]=> string(5) "hello" ["Anothera"]=> int(1) ["d"]=> string(3) "wow" } object(stdClass)#2 (5) { ["a":"Test":private]=> int(0) ["b":protected]=> bool(false) ["c"]=> string(5) "hello" ["a":"Another":private]=> int(1) ["d"]=> string(3) "wow" }
Output for 8.0.0 - 8.0.30
hellowow Warning: Undefined property: stdClass::$b in /in/aFbJW on line 25 Warning: Undefined property: stdClass::$a in /in/aFbJW on line 25 array(5) { ["Anothera"]=> int(1) ["*b"]=> bool(false) ["d"]=> string(3) "wow" ["c"]=> string(5) "hello" ["Testa"]=> int(0) } object(stdClass)#2 (5) { ["a":"Another":private]=> int(1) ["b":protected]=> bool(false) ["d"]=> string(3) "wow" ["c"]=> string(5) "hello" ["a":"Test":private]=> int(0) }
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.7, 7.2.29 - 7.2.33, 7.3.12 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
hellowow Notice: Undefined property: stdClass::$b in /in/aFbJW on line 25 Notice: Undefined property: stdClass::$a in /in/aFbJW on line 25 array(5) { ["Anothera"]=> int(1) ["*b"]=> bool(false) ["d"]=> string(3) "wow" ["c"]=> string(5) "hello" ["Testa"]=> int(0) } object(stdClass)#2 (5) { ["a":"Another":private]=> int(1) ["b":protected]=> bool(false) ["d"]=> string(3) "wow" ["c"]=> string(5) "hello" ["a":"Test":private]=> int(0) }
Output for 5.4.0 - 5.4.45, 7.3.32 - 7.3.33, 7.4.26
hellowowarray(5) { ["Anothera"]=> int(1) ["*b"]=> bool(false) ["d"]=> string(3) "wow" ["c"]=> string(5) "hello" ["Testa"]=> int(0) } object(stdClass)#2 (5) { ["a":"Another":private]=> int(1) ["b":protected]=> bool(false) ["d"]=> string(3) "wow" ["c"]=> string(5) "hello" ["a":"Test":private]=> int(0) }
Output for 5.3.0 - 5.3.29
hellowowarray(5) { ["Anothera"]=> int(1) ["*b"]=> bool(false) ["d"]=> string(3) "wow" ["Testa"]=> int(0) ["c"]=> string(5) "hello" } object(stdClass)#2 (5) { ["a":"Another":private]=> int(1) ["b":protected]=> bool(false) ["d"]=> string(3) "wow" ["a":"Test":private]=> int(0) ["c"]=> string(5) "hello" }
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
hellowowarray(5) { ["Anothera"]=> int(1) ["*b"]=> bool(false) ["d"]=> string(3) "wow" ["Testa"]=> int(0) ["c"]=> string(5) "hello" } object(stdClass)#2 (5) { ["a:private"]=> int(1) ["b:protected"]=> bool(false) ["d"]=> string(3) "wow" ["a:private"]=> int(0) ["c"]=> string(5) "hello" }
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/aFbJW</b> on line <b>6</b><br />
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
<br /> <b>Parse error</b>: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in <b>/in/aFbJW</b> on line <b>6</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/aFbJW</b> on line <b>6</b><br />
Process exited with code 255.

preferences:
224.85 ms | 401 KiB | 341 Q