2016-08-03 90 views
0

找上我的Apache错误日志文件,我检查了这样的警告:如何解决警告JSON_BIGINT_AS_STRING未执行?

PHP Warning: json_decode(): option JSON_BIGINT_AS_STRING not implemented in /../codebird.php on line 2517 

它提到了我使用自动后在Twitter上从我的博客的脚本。

这是有罪的功能:

protected function _parseApiReply($reply) 
    { 
    $need_array = $this->_return_format === CODEBIRD_RETURNFORMAT_ARRAY; 
    if ($reply === '[]') { 
     switch ($this->_return_format) { 
     case CODEBIRD_RETURNFORMAT_ARRAY: 
      return []; 
     case CODEBIRD_RETURNFORMAT_JSON: 
      return '{}'; 
     case CODEBIRD_RETURNFORMAT_OBJECT: 
      return new \stdClass; 
     } 
    } 
    if (! $parsed = json_decode($reply, $need_array, 512, JSON_BIGINT_AS_STRING)) { 
     if ($reply) { 
     // assume query format 
     $reply = explode('&', $reply); 
     foreach ($reply as $element) { 
      if (stristr($element, '=')) { 
      list($key, $value) = explode('=', $element, 2); 
      $parsed[$key] = $value; 
      } else { 
      $parsed['message'] = $element; 
      } 
     } 
     } 
     $reply = json_encode($parsed); 
    } 
    switch ($this->_return_format) { 
     case CODEBIRD_RETURNFORMAT_ARRAY: 
     return $parsed; 
     case CODEBIRD_RETURNFORMAT_JSON: 
     return $reply; 
     case CODEBIRD_RETURNFORMAT_OBJECT: 
     return (object) $parsed; 
    } 
    return $parsed; 
    } 
} 

为什么如果标题太长,我得到这个警告,并没有张贴在Twitter?

P.S.

我已经安装PHP 5.5.9但问题仍然相同。

+1

看起来像那台机器上PHP的更新已经过期了。 –

+0

@ N.B。 :)是的,我已经更新了这个问题 – NineCattoRules

+0

我在5.6,它的工作原理,我没有尝试7,但我会猜测并说它也可以在那里工作。 –

回答

1

JSON_BIGINT_AS_STRING option自PHP 5.4起才可用。你可以删除它,但是如果你的JSON响应中包含的数字太大,它们会溢出。

进一步研究,似乎有一些problems with JSON's license导致基于Debian的发行版不提供标准JSON扩展的包。他们与定义常量JSON_C_VERSION可以用于检查一个主要兼容的版本来替换它:

if (defined("JSON_C_VERSION") || version_compare(PHP_VERSION, '5.4.0', '<')) { 
    json_decode($reply, $need_array, 512); 
} else { 
    json_decode($reply, $need_array, 512, JSON_BIGINT_AS_STRING); 
} 

或者,直接删除第四个参数。我一直使用RHEL发行版的Scientific Linux,因此以前从未遇到过这个问题。

+0

好的谢谢:)我已经安装了'PHP 5.5.9' – NineCattoRules

+0

查看我的更新;看起来你是一些开源许可证欺诈的受害者。 – miken32

+0

删除第四个参数不是一个解决方案。 – NineCattoRules