3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: Undefined variable $prefixes in /in/AlJ1F on line 10 Deprecated: Creation of dynamic property G::$ is deprecated in /in/AlJ1F on line 10 Fatal error: Uncaught TypeError: array_push(): Argument #1 ($array) must be of type array, null given in /in/AlJ1F:10 Stack trace: #0 /in/AlJ1F(10): array_push(NULL, 'b') #1 /in/AlJ1F(14): G->test('a', 'b') #2 {main} thrown in /in/AlJ1F on line 10
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Warning: Undefined variable $prefixes in /in/AlJ1F on line 10 Fatal error: Uncaught TypeError: array_push(): Argument #1 ($array) must be of type array, null given in /in/AlJ1F:10 Stack trace: #0 /in/AlJ1F(10): array_push(NULL, 'b') #1 /in/AlJ1F(14): G->test('a', 'b') #2 {main} thrown in /in/AlJ1F on line 10
Process exited with code 255.
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
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.3.32 - 7.3.33
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.5.24 - 5.5.35, 5.6.8 - 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.

preferences:
204.42 ms | 402 KiB | 183 Q