我正在尝试将我的一个PHP应用程序升级到PHP7。一切都很好,除了一个。我看到json_last_error()在PHP7中返回一个不同的值。
$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' --compressedPHP5返回0 (JSON_ERROR_NONE)
PHP7返回4 (JSON_ERROR_SYNTAX)
如果有变化,我看过正式的文档,但是我找不到任何信息。
json_decode()或json_last_error()函数是否有更改?
发布于 2018-10-28 12:23:31
根据json_decode(),任何"falsy“字符串值(意为空字符串、null和false)都将导致JSON语法错误。因此,是的,PHP5和PHP7之间的json_decode()发生了变化,但是json_last_error()没有改变。
json_encode() 7.0.0中的变化量
一个空PHP字符串或值,在转换为string之后是空字符串(NULL,FALSE),将导致JSON语法错误。
https://stackoverflow.com/questions/53030698
复制相似问题