3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = [ 'key1' => 'value1', 'key2' => 'value2', ]; foreach ($array as $key => $value) { $object = (object) $value; var_dump($object); echo $object->$key; }
based on E4WmY
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
object(stdClass)#1 (1) { ["scalar"]=> string(6) "value1" } Notice: Undefined property: stdClass::$key1 in /in/1caOb on line 11 object(stdClass)#2 (1) { ["scalar"]=> string(6) "value2" } Notice: Undefined property: stdClass::$key2 in /in/1caOb on line 11