2016-08-03 235 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