小编vos*_*kys的帖子

从PHP 7.1.x迁移到PHP 7.2.x json_decode()更改

官方文件说:

如果第二个参数(关联)为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);
Run Code Online (Sandbox Code Playgroud)

但是,仅最后一次打印以数组形式打印。

我理解不对吗?

php migration php-7.2 jsondecoder

1
推荐指数
1
解决办法
2734
查看次数

标签 统计

jsondecoder ×1

migration ×1

php ×1

php-7.2 ×1