3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $arr = (object) [ 'children' => [] ]; $arr->children[] = 1; print_r($arr); class Test { public function test(){ $arr = (object) [ 'children' => [] ]; $arr->children[] = 1; return $arr; } } $o = new Test(); $o->test(); print_r( $o->test() );
based on 5qKBH
Output for 7.0.2 - 7.1.7, 7.2.0
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Test has a deprecated constructor in /in/PJR7m on line 10 stdClass Object ( [children] => Array ( [0] => 1 ) ) stdClass Object ( [children] => Array ( [0] => 1 ) )
Output for 7.1.10

Process exited with code 137.
Output for 7.0.0 - 7.0.1
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Test has a deprecated constructor in /in/PJR7m on line 10 stdClass Object ( [children] => Array ( [0] => 1 ) ) stdClass Object ( [children] => Array ( [0] => 1 [1] => 1 ) )
Output for 5.4.10 - 5.6.28
stdClass Object ( [children] => Array ( [0] => 1 ) ) stdClass Object ( [children] => Array ( [0] => 1 ) )
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/PJR7m on line 3
Process exited with code 255.