@@ -996,6 +996,24 @@ protected function _mapFnInlineParams($method, &$apiparams)
996996 return [$ method , $ method_template ];
997997 }
998998
999+ /**
1000+ * Avoids any JSON_BIGINT_AS_STRING errors
1001+ *
1002+ * @param string $data JSON data to decode
1003+ * @param int optional $need_array Decode as array, otherwise as object
1004+ *
1005+ * @return array|object The decoded object
1006+ */
1007+ protected function _json_decode ($ data , $ need_array = false )
1008+ {
1009+ if (!(defined ('JSON_C_VERSION ' ) && PHP_INT_SIZE > 4 )) {
1010+ return json_decode ($ data , $ need_array , 512 , JSON_BIGINT_AS_STRING );
1011+ }
1012+ $ max_int_length = strlen ((string ) PHP_INT_MAX ) - 1 ;
1013+ $ json_without_bigints = preg_replace ('/:\s*(-?\d{ ' .$ max_int_length .',})/ ' , ': "$1" ' , $ data );
1014+ $ obj = json_decode ($ json_without_bigints , $ need_array );
1015+ return $ obj ;
1016+ }
9991017
10001018 /**
10011019 * Uncommon API methods
@@ -1336,7 +1354,7 @@ protected function _parseBearerReply($result, $httpstatus)
13361354 break ;
13371355 case CODEBIRD_RETURNFORMAT_JSON :
13381356 if ($ httpstatus === 200 ) {
1339- $ parsed = json_decode ($ reply, false , 512 , JSON_BIGINT_AS_STRING );
1357+ $ parsed = $ this -> _json_decode ($ reply );
13401358 self ::setBearerToken ($ parsed ->access_token );
13411359 }
13421360 break ;
@@ -2232,7 +2250,7 @@ protected function _appendHttpStatusAndRate($reply, $httpstatus, $rate)
22322250 $ reply ->rate = $ rate ;
22332251 break ;
22342252 case CODEBIRD_RETURNFORMAT_JSON :
2235- $ reply = json_decode ($ reply );
2253+ $ reply = $ this -> _json_decode ($ reply );
22362254 $ reply ->httpstatus = $ httpstatus ;
22372255 $ reply ->rate = $ rate ;
22382256 $ reply = json_encode ($ reply );
@@ -2566,7 +2584,7 @@ protected function _parseApiReply($reply)
25662584 return new \stdClass ;
25672585 }
25682586 }
2569- if (! $ parsed = json_decode ($ reply , $ need_array, 512 , JSON_BIGINT_AS_STRING )) {
2587+ if (! $ parsed = $ this -> _json_decode ($ reply , $ need_array )) {
25702588 if ($ reply ) {
25712589 // assume query format
25722590 $ reply = explode ('& ' , $ reply );
0 commit comments