3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestClass { public function baz() { echo "Worked!"; } } $foo = 'bam'; $bam = ['bar' => new TestClass()]; var_dump($$foo); var_dump($$foo['bar']); $$foo['bar']->baz(); // function getResult() { // return "string"; // } // echo getResult(){0};
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
array(1) { ["bar"]=> object(TestClass)#1 (0) { } } object(TestClass)#1 (0) { } Worked!
Output for 5.6.8 - 5.6.28
array(1) { ["bar"]=> object(TestClass)#1 (0) { } } Warning: Illegal string offset 'bar' in /in/ZWeQ3 on line 12 Notice: Undefined variable: b in /in/ZWeQ3 on line 12 NULL Warning: Illegal string offset 'bar' in /in/ZWeQ3 on line 14 Notice: Undefined variable: b in /in/ZWeQ3 on line 14 Fatal error: Call to a member function baz() on null in /in/ZWeQ3 on line 14
Process exited with code 255.
Output for 5.5.24 - 5.5.35
array(1) { ["bar"]=> object(TestClass)#1 (0) { } } Warning: Illegal string offset 'bar' in /in/ZWeQ3 on line 12 Notice: Undefined variable: b in /in/ZWeQ3 on line 12 NULL Warning: Illegal string offset 'bar' in /in/ZWeQ3 on line 14 Notice: Undefined variable: b in /in/ZWeQ3 on line 14 Fatal error: Call to a member function baz() on a non-object in /in/ZWeQ3 on line 14
Process exited with code 255.

preferences:
155.46 ms | 401 KiB | 177 Q