3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $obj = new stdClass(); $obj->bar = "xyz"; $data = array("foo" => "bar"); $key = "foo"; $obj->${'data'[$key]}; // Syntax error $obj->{$data[$key]}; // Works $obj->${'key'}; // E_NOTICE. Does not work $obj->{$key}; // Works
based on b0Tgm
Output for 7.1.0 - 7.2.0
Warning: Illegal string offset 'foo' in /in/SD2cC on line 7 Notice: Undefined variable: d in /in/SD2cC on line 7 Notice: Undefined property: stdClass::$ in /in/SD2cC on line 7 Notice: Undefined property: stdClass::$foo in /in/SD2cC on line 10 Notice: Undefined property: stdClass::$foo in /in/SD2cC on line 11
Output for 7.0.0 - 7.0.20
Warning: Illegal string offset 'foo' in /in/SD2cC on line 7 Notice: Undefined variable: d in /in/SD2cC on line 7 Fatal error: Uncaught Error: Cannot access empty property in /in/SD2cC:7 Stack trace: #0 {main} thrown in /in/SD2cC on line 7
Process exited with code 255.
Output for 5.5.24 - 5.6.28
Warning: Illegal string offset 'foo' in /in/SD2cC on line 7 Notice: Undefined variable: d in /in/SD2cC on line 7 Fatal error: Cannot access empty property in /in/SD2cC on line 7
Process exited with code 255.
Output for 5.3.21 - 5.4.45
Parse error: syntax error, unexpected '[' in /in/SD2cC on line 7
Process exited with code 255.