dsce23640 2019-04-12 13:36
浏览 75
已采纳

PHP 5.6返回结果,如PHP 5.2

We recently occured weird error like:

json_decode(): integer overflow detected in Command line code on line 1

On our server with PHP 5.6.30(unforunately i don't know how it was built).

We had code like json_decode('{"key":999999999999999999999999999999999999999999999999999}', true)

What actually happened that we indeed had too big integer value. But what was interesting i run this code on 3v4l and in case of too big integer it should be converted to float - https://3v4l.org/IdJpZ

But what is more interesting that on php 5.2.0-5.2.3 it actually converts this number to max integer value instead, like:

array(1) {
  ["key"]=>
  int(9223372036854775807)
}

So this is exactly output from this code and php -v:

$ php -r "var_dump(json_decode('{\"key\":999999999999999999999999999999999999999999999999999}', true));"
PHP Notice:  json_decode(): integer overflow detected in Command line code on line 1
array(1) {
  ["key"]=>
  int(9223372036854775807)
}
$ php -v
PHP 5.6.30-0+deb8u1 (cli) (built: Feb  8 2017 08:50:21) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Do you have any idea why our PHP 5.6.30 did the same behavior as PHP 5.2.0-5.2.3?

Also we use extension which actually requries at least PHP 5.4 and it works fine. Also we are using things like [] and it works fine too.

  • 写回答

1条回答 默认 最新

  • dongtan7639 2019-04-12 13:53
    关注

    Okay i figured out what is going on. We actually have jsonc extension which is drop-in replacement for native json support in php.

    This issue actually pointed me to good direction - https://github.com/remicollet/pecl-json-c/issues/13

    Indeed we just have outdated jsonc version and that's it.

    $ php --ri json
    
    json
    
    json support => enabled
    json version => 1.3.6
    JSON-C headers version => 0.11.99
    JSON-C library version => 0.11.99
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀