3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class G { public $prefixes = array(); public function test($prefix, $baseDir) { if (!isset($this->prefixes[$prefix])) { $this->prefixes[$prefix] = []; } array_push($this->$prefixes[$prefix], $baseDir); } } $l = new G(); $l->test("a", "b"); var_dump($l);
based on rEgba
Output for 7.1.0 - 7.2.0
Notice: Undefined variable: prefixes in /in/AlJ1F on line 10 Warning: array_push() expects parameter 1 to be array, null given in /in/AlJ1F on line 10 object(G)#1 (2) { ["prefixes"]=> array(1) { ["a"]=> array(0) { } } [""]=> array(1) { ["a"]=> NULL } }
Output for 7.0.0 - 7.0.20
Notice: Undefined variable: prefixes in /in/AlJ1F on line 10 Fatal error: Uncaught Error: Cannot access empty property in /in/AlJ1F:10 Stack trace: #0 /in/AlJ1F(14): G->test('a', 'b') #1 {main} Next Error: Cannot access empty property in /in/AlJ1F:10 Stack trace: #0 /in/AlJ1F(14): G->test('a', 'b') #1 {main} thrown in /in/AlJ1F on line 10
Process exited with code 255.
Output for 5.4.10 - 5.6.28
Notice: Undefined variable: prefixes in /in/AlJ1F on line 10 Fatal error: Cannot access empty property in /in/AlJ1F on line 10
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/AlJ1F on line 8
Process exited with code 255.