3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $obj = new stdClass(); $obj->bar = "xyz"; $data = array("foo" => "bar"); $key = "foo"; // echo $obj->${data[$key]}; syntax error echo $obj->{$data[$key]}; $member = $data[$key]; echo $obj->${'member'}; echo $obj->{$member}; echo ${'data'}[$key]; // of course, this works echo ${data[$key]}; // of course, this works echo "\n${data[$key]}\n"; // of course, this works echo "{${'data'}[$key]}"; // of course, this works echo "{$data[$key]}";
based on jK0cj
Output for 7.2.0
xyzxyzxyzbar Warning: Use of undefined constant data - assumed 'data' (this will throw an Error in a future version of PHP) in /in/HYGZc on line 15 Warning: Illegal string offset 'foo' in /in/HYGZc on line 15 Notice: Undefined variable: d in /in/HYGZc on line 15 bar barbar
Output for 5.6.8 - 7.1.10
xyzxyzxyzbar Notice: Use of undefined constant data - assumed 'data' in /in/HYGZc on line 15 Warning: Illegal string offset 'foo' in /in/HYGZc on line 15 Notice: Undefined variable: d in /in/HYGZc on line 15 bar barbar
Output for 5.3.21 - 5.5.35
Parse error: syntax error, unexpected '[' in /in/HYGZc on line 15
Process exited with code 255.