3v4l.org

run code in 300+ PHP versions simultaneously
<?php $obj = new stdClass(); $obj->bar = "xyz"; $data = array("foo" => "bar"); $key = "foo"; //$obj->${'data'[$key]}; // Syntax error $obj->{$data[$key]}; // Works $obj->${key}; // E_NOTICE. Does not work $obj->{$key}; // Works
Output for 8.1.28, 8.2.17 - 8.2.18, 8.3.4 - 8.3.6
Fatal error: Uncaught Error: Undefined constant "key" in /in/J78h5:10 Stack trace: #0 {main} thrown in /in/J78h5 on line 10
Process exited with code 255.
Output for 7.2.0, 7.2.9 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
Warning: Use of undefined constant key - assumed 'key' (this will throw an Error in a future version of PHP) in /in/J78h5 on line 10 Notice: Undefined property: stdClass::$foo in /in/J78h5 on line 10 Notice: Undefined property: stdClass::$foo in /in/J78h5 on line 11
Output for 5.5.19, 5.5.36, 5.6.8 - 5.6.9, 5.6.11 - 5.6.14, 5.6.25 - 5.6.27, 5.6.30 - 5.6.31, 5.6.39, 7.0.4 - 7.0.5, 7.0.7, 7.0.16, 7.0.19, 7.0.30 - 7.0.31, 7.1.1, 7.1.7, 7.1.21, 7.2.1 - 7.2.8

Process exited with code 137.
Output for 5.5.0 - 5.5.18, 5.5.20 - 5.5.35, 5.5.37 - 5.5.38, 5.6.0 - 5.6.7, 5.6.10, 5.6.15 - 5.6.24, 5.6.28 - 5.6.29, 5.6.32 - 5.6.38, 5.6.40, 7.0.0 - 7.0.3, 7.0.6, 7.0.8 - 7.0.15, 7.0.17 - 7.0.18, 7.0.20 - 7.0.29, 7.0.32 - 7.0.33, 7.1.0, 7.1.2 - 7.1.6, 7.1.8 - 7.1.20, 7.1.22 - 7.1.33
Notice: Use of undefined constant key - assumed 'key' in /in/J78h5 on line 10 Notice: Undefined property: stdClass::$foo in /in/J78h5 on line 10 Notice: Undefined property: stdClass::$foo in /in/J78h5 on line 11

preferences:
151.17 ms | 406 KiB | 202 Q