在我看来,PHP5.5中的常量JSON_BIGINT_AS_STRING已从json_decode()中删除。
我使用PHP "5.5.3-1ubuntu2“(Ubuntu13.10),并从PHP5.4(Ubuntu13.04)更新后获得了此错误:
警告: json_decode():选项JSON_BIGINT_AS_STRING未在.
有证据证明这件事被删除了吗?
编辑:
我不需要这个函数,所以我添加了一个常量:
define('USE_JSON_BIGINT_AS_STRING',(!version_compare(PHP_VERSION,'5.5', '>=') and defined('JSON_BIGINT_AS_STRING')));无论在何处使用json_decode(),我都使用以下内容:
if(USE_JSON_BIGINT_AS_STRING) $j= json_decode($json ,true, 512, JSON_BIGINT_AS_STRING );
else $j= json_decode($json,true );发布于 2015-01-12 20:06:03
如前所述,此错误似乎来自于一个buggy版本的pecl c,由于许可证问题,Ubuntu将其打包为php5-json的别名。
感谢firebase/php-jwt项目,我发现的一项工作是检查由project c而不是USE_JSON_BIGINT_AS_STRING设置的JSON_C_VERSION常量。(因为USE_JSON_BIGINT_AS_STRING是定义的,但没有实现)。
下面是来自JWT项目的代码
<?php
if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) {
/** In PHP >=5.4.0, json_decode() accepts an options parameter, that allows you
* to specify that large ints (like Steam Transaction IDs) should be treated as
* strings, rather than the PHP default behaviour of converting them to floats.
*/
$obj = json_decode($input, false, 512, JSON_BIGINT_AS_STRING);
} else {
/** Not all servers will support that, however, so for older versions we must
* manually detect large ints in the JSON string and quote them (thus converting
*them to strings) before decoding, hence the preg_replace() call.
*/
$max_int_length = strlen((string) PHP_INT_MAX) - 1;
$json_without_bigints = preg_replace('/:\s*(-?\d{'.$max_int_length.',})/', ': "$1"', $input);
$obj = json_decode($json_without_bigints);
}发布于 2013-10-22 15:07:31
看起来,由于许可证问题,对于某些Linux发行版来说,这是介绍,而且您使用的是受影响的json-c PECL模块。
我的建议是使用新版本的模块。
https://stackoverflow.com/questions/19520487
复制相似问题