3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array(1, 2, 4); $obj = (object)$arr; var_dump($obj); var_dump($obj->{0}, $obj->{1}, $obj->{2}); var_dump($obj->{'0'}, $obj->{'1'}, $obj->{'2'});
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.21, 7.4.0 - 7.4.10, 8.0.0alpha1 - beta3
object(stdClass)#1 (3) { ["0"]=> int(1) ["1"]=> int(2) ["2"]=> int(4) } int(1) int(2) int(4) int(1) int(2) int(4)
Output for 5.2.6 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.24, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25
object(stdClass)#1 (3) { [0]=> int(1) [1]=> int(2) [2]=> int(4) } Notice: Undefined property: stdClass::$0 in /in/55kiC on line 7 Notice: Undefined property: stdClass::$1 in /in/55kiC on line 7 Notice: Undefined property: stdClass::$2 in /in/55kiC on line 7 NULL NULL NULL Notice: Undefined property: stdClass::$0 in /in/55kiC on line 8 Notice: Undefined property: stdClass::$1 in /in/55kiC on line 8 Notice: Undefined property: stdClass::$2 in /in/55kiC on line 8 NULL NULL NULL
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.5
object(stdClass)#1 (3) { [0]=> int(1) [1]=> int(2) [2]=> int(4) } Notice: Undefined property: stdClass::$0 in /in/55kiC on line 7 Notice: Undefined property: stdClass::$1 in /in/55kiC on line 7 Notice: Undefined property: stdClass::$2 in /in/55kiC on line 7 NULL NULL NULL Notice: Undefined property: stdClass::$0 in /in/55kiC on line 8 Notice: Undefined property: stdClass::$1 in /in/55kiC on line 8 Notice: Undefined property: stdClass::$2 in /in/55kiC on line 8 NULL NULL NULL
Output for 4.3.3 - 4.3.11, 4.4.0 - 4.4.9
Fatal error: Property name must be a string in /in/55kiC on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.2
object(stdClass)(3) { [0]=> int(1) [1]=> int(2) [2]=> int(4) }
Process exited with code 139.