官方文档说:
如果第二个参数 (assoc) 为 NULL,则现在使用 json_decode() 函数选项 JSON_OBJECT_AS_ARRAY。以前,JSON_OBJECT_AS_ARRAY 总是被忽略。
此代码(AFAIK)完成此更改和条件:
<?php
$an_object = new StdClass();
$an_object->some_atrribute = "value 1";
$an_object->other_atrribute = "value 2";
//an object
print_r($an_object);
$encoded = json_encode($an_object);
//here (null is passed in the second parameter)
$output = json_decode($encoded,null,512);
//using 7.2 should be array, however it is an object
print_r($output);
//array
$output = json_decode($encoded,true);
print_r($output);
但是只有最后一个打印,打印为数组。
我理解错了吗?