3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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
based on csIqe
Output for 7.2.0
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.3.21 - 7.1.10
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