3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $object = new stdClass(); $object->{'1'} = 'one'; //echo $object->{'1'}; $array = (array) $object; $test = '1'; echo $array[$test]; echo $array['1']; //var_dump($array); /* produces array(1) { ["1"]=> string(3) "one" } */ //none of the following will work $key = '1'; echo $array[1], $array['1'], $array["1"], $array[(string)1], $array[$key];
based on EcMWH
Output for 7.2.0
oneoneoneoneoneoneone
Output for 5.4.9 - 7.1.10
Notice: Undefined offset: 1 in /in/a0H8t on line 8 Notice: Undefined offset: 1 in /in/a0H8t on line 9 Notice: Undefined offset: 1 in /in/a0H8t on line 20 Notice: Undefined offset: 1 in /in/a0H8t on line 20 Notice: Undefined offset: 1 in /in/a0H8t on line 20 Notice: Undefined offset: 1 in /in/a0H8t on line 20 Notice: Undefined offset: 1 in /in/a0H8t on line 20
Output for 5.3.19 - 5.3.29
Notice: Undefined index: 1 in /in/a0H8t on line 8 Notice: Undefined index: 1 in /in/a0H8t on line 9 Notice: Undefined offset: 1 in /in/a0H8t on line 20 Notice: Undefined index: 1 in /in/a0H8t on line 20 Notice: Undefined index: 1 in /in/a0H8t on line 20 Notice: Undefined index: 1 in /in/a0H8t on line 20 Notice: Undefined index: 1 in /in/a0H8t on line 20