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 ${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]}";
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /in/HYGZc on line 17 xyzxyzxyzbar Fatal error: Uncaught Error: Undefined constant "data" in /in/HYGZc:15 Stack trace: #0 {main} thrown in /in/HYGZc on line 15
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
xyzxyzxyzbar Fatal error: Uncaught Error: Undefined constant "data" in /in/HYGZc:15 Stack trace: #0 {main} thrown in /in/HYGZc on line 15
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
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 7.3.32 - 7.3.33
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 bar barbar
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
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.5.0 - 5.5.38
Parse error: syntax error, unexpected '[' in /in/HYGZc on line 15
Process exited with code 255.

preferences:
257.44 ms | 401 KiB | 330 Q