3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestClass { public function baz() { echo "Worked!"; } } $foo = 'bam'; $bam = ['bar' => new TestClass()]; $output = $$foo; var_dump($$foo); // Correctly reads this var_dump(${$foo['bar']}); var_dump($$foo['bar']); // Change $$foo to $output // $$foo['bar']->baz(); // function getResult() { // return "string"; // } // echo getResult(){0};
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
array(1) { ["bar"]=> object(TestClass)#1 (0) { } } Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/O7bOb:14 Stack trace: #0 {main} thrown in /in/O7bOb on line 14
Process exited with code 255.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
array(1) { ["bar"]=> object(TestClass)#1 (0) { } } Warning: Illegal string offset 'bar' in /in/O7bOb on line 14 Notice: Undefined variable: b in /in/O7bOb on line 14 NULL object(TestClass)#1 (0) { }
Output for 7.3.32 - 7.3.33
array(1) { ["bar"]=> object(TestClass)#1 (0) { } } Warning: Illegal string offset 'bar' in /in/O7bOb on line 14 NULL object(TestClass)#1 (0) { }
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38
array(1) { ["bar"]=> object(TestClass)#1 (0) { } } Warning: Illegal string offset 'bar' in /in/O7bOb on line 14 Notice: Undefined variable: b in /in/O7bOb on line 14 NULL Warning: Illegal string offset 'bar' in /in/O7bOb on line 15 Notice: Undefined variable: b in /in/O7bOb on line 15 NULL

preferences:
194.81 ms | 402 KiB | 294 Q