3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{"1":"A"}'; $arrWorks = json_decode($json, true); var_dump($arrWorks); var_dump($arrWorks[1], $arrWorks['1']); echo "\n=================\n"; $arrDoesntWork = get_object_vars(json_decode($json)); var_dump($arrDoesntWork); var_dump($arrDoesntWork[1], $arrDoesntWork['1']);
Output for 5.5.0 - 5.5.36, 5.6.0 - 5.6.29, 7.0.20, 7.1.5 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
array(1) { [1]=> string(1) "A" } string(1) "A" string(1) "A" ================= array(1) { [1]=> string(1) "A" } string(1) "A" string(1) "A"
Output for 7.0.0 - 7.0.14, 7.1.0
array(1) { [1]=> string(1) "A" } string(1) "A" string(1) "A" ================= array(1) { ["1"]=> string(1) "A" } Notice: Undefined offset: 1 in /in/bbleq on line 12 Notice: Undefined offset: 1 in /in/bbleq on line 12 NULL NULL

preferences:
58.73 ms | 407 KiB | 5 Q