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 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas
  • ¥15 蓝牙硬件,可以用哪几种方法控制手机点击和滑动
  • ¥15 生物医学数据分析。基础课程就v经常唱课程舅成牛逼
  • ¥15 云环境云开发云函数对接微信商户中的分账功能
  • ¥15 空间转录组CRAD遇到问题
  • ¥20 materialstudio计算氢键脚本问题