【发布时间】:2018-05-24 19:30:52
【问题描述】:
现在使用 json_decode() 函数选项 JSON_OBJECT_AS_ARRAY 如果第二个参数 (assoc) 为 NULL。之前, 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);
但是只有最后一次打印,打印为数组。
我理解错了吗?
【问题讨论】:
标签: php migration php-7.2 jsondecoder