3v4l.org

run code in 300+ PHP versions simultaneously
<?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]}";
Output for 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /in/7dQKJ on line 13 Deprecated: Using ${expr} (variable variables) in strings is deprecated, use {${expr}} instead in /in/7dQKJ on line 14 xyz Fatal error: Uncaught Error: Undefined constant "member" in /in/7dQKJ:10 Stack trace: #0 {main} thrown in /in/7dQKJ on line 10
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27
xyz Fatal error: Uncaught Error: Undefined constant "member" in /in/7dQKJ:10 Stack trace: #0 {main} thrown in /in/7dQKJ on line 10
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
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 7.3.32 - 7.3.33
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 Array[foo] bar
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20
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

preferences:
172.17 ms | 402 KiB | 178 Q