PHP 5 和 7 - json_last_error 差异
PHP 5 and 7 - json_last_error difference
我正在尝试将我的一个 PHP 应用程序升级到 PHP7。一切都很好,除了一个。我在 PHP7.
中看到 json_last_error()
returns 不同的值
$input = file_get_contents('php://input');
$json = json_decode($input, true);
print_r(json_last_error());
当我
curl 'http://localhost/test.php' -H 'Content-Type: application/json' --compressed
PHP 5 returns 0 (JSON_ERROR_NONE)
PHP 7 returns 4 (JSON_ERROR_SYNTAX)
我查看了官方文档是否有变化,但找不到任何信息。
json_decode()
或 json_last_error()
函数有变化吗?
根据 changelog of json_decode()
,任何 "falsy" 字符串值(表示空字符串,null
和 false
)将导致 JSON 语法错误。所以是的,json_decode()
在 PHP 5 和 PHP 7 之间发生了变化。但是 json_last_error()
没有改变。
json_encode()
的 7.0.0 中的变更日志:
An empty PHP string or value that after casting to string is an empty string (NULL, FALSE) results in JSON syntax error.
我正在尝试将我的一个 PHP 应用程序升级到 PHP7。一切都很好,除了一个。我在 PHP7.
中看到json_last_error()
returns 不同的值
$input = file_get_contents('php://input');
$json = json_decode($input, true);
print_r(json_last_error());
当我
curl 'http://localhost/test.php' -H 'Content-Type: application/json' --compressed
PHP 5 returns 0 (JSON_ERROR_NONE)
PHP 7 returns 4 (JSON_ERROR_SYNTAX)
我查看了官方文档是否有变化,但找不到任何信息。
json_decode()
或 json_last_error()
函数有变化吗?
根据 changelog of json_decode()
,任何 "falsy" 字符串值(表示空字符串,null
和 false
)将导致 JSON 语法错误。所以是的,json_decode()
在 PHP 5 和 PHP 7 之间发生了变化。但是 json_last_error()
没有改变。
json_encode()
的 7.0.0 中的变更日志:
An empty PHP string or value that after casting to string is an empty string (NULL, FALSE) results in JSON syntax error.