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 "\n${'data'}[$key]\n"; echo "{$data[$key]}";
based on ldZKl
Output for 7.2.0
xyz Warning: Use of undefined constant member - assumed 'member' (this will throw an Error in a future version of PHP) in /in/7dQKJ on line 10 xyzxyzbar Notice: Array to string conversion in /in/7dQKJ on line 14 Array[foo] bar
Output for 5.4.11 - 7.1.10
xyz Notice: Use of undefined constant member - assumed 'member' in /in/7dQKJ on line 10 xyzxyzbar Notice: Array to string conversion in /in/7dQKJ on line 14 Array[foo] bar
Output for 5.3.21 - 5.3.29
xyz Notice: Use of undefined constant member - assumed 'member' in /in/7dQKJ on line 10 xyzxyzbar Array[foo] bar