3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $data = ["foo"=>"bar"]; $key = "foo"; $obj = new stdClass; $obj->bar = 'xyz'; echo "{$obj->{${data[$key]}}}\n"; echo "{$obj->{ ${'data'}[$key] }}\n"; echo "{$obj->{ ${data}[$key] }}\n";
based on EkvkY
Output for 7.2.0
Warning: Use of undefined constant data - assumed 'data' (this will throw an Error in a future version of PHP) in /in/nCXJL on line 6 Warning: Illegal string offset 'foo' in /in/nCXJL on line 6 Notice: Undefined variable: d in /in/nCXJL on line 6 Notice: Undefined property: stdClass::$ in /in/nCXJL on line 6 xyz Warning: Use of undefined constant data - assumed 'data' (this will throw an Error in a future version of PHP) in /in/nCXJL on line 8 xyz
Output for 7.1.0 - 7.1.10
Notice: Use of undefined constant data - assumed 'data' in /in/nCXJL on line 6 Warning: Illegal string offset 'foo' in /in/nCXJL on line 6 Notice: Undefined variable: d in /in/nCXJL on line 6 Notice: Undefined property: stdClass::$ in /in/nCXJL on line 6 xyz Notice: Use of undefined constant data - assumed 'data' in /in/nCXJL on line 8 xyz
Output for 7.0.0 - 7.0.20
Notice: Use of undefined constant data - assumed 'data' in /in/nCXJL on line 6 Warning: Illegal string offset 'foo' in /in/nCXJL on line 6 Notice: Undefined variable: d in /in/nCXJL on line 6 Fatal error: Uncaught Error: Cannot access empty property in /in/nCXJL:6 Stack trace: #0 {main} thrown in /in/nCXJL on line 6
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Notice: Use of undefined constant data - assumed 'data' in /in/nCXJL on line 6 Warning: Illegal string offset 'foo' in /in/nCXJL on line 6 Notice: Undefined variable: d in /in/nCXJL on line 6 Fatal error: Cannot access empty property in /in/nCXJL on line 6
Process exited with code 255.
Output for 5.4.11 - 5.5.35
Parse error: syntax error, unexpected '[' in /in/nCXJL on line 6
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/nCXJL on line 2
Process exited with code 255.