3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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};
based on 0C5up
Output for 7.0.0 - 7.2.0
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 5.4.11 - 5.6.28
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
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/O7bOb on line 9
Process exited with code 255.