@@ -996,6 +996,24 @@ protected function _mapFnInlineParams($method, &$apiparams)
996
996
return [$ method , $ method_template ];
997
997
}
998
998
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
+ }
999
1017
1000
1018
/**
1001
1019
* Uncommon API methods
@@ -1336,7 +1354,7 @@ protected function _parseBearerReply($result, $httpstatus)
1336
1354
break ;
1337
1355
case CODEBIRD_RETURNFORMAT_JSON :
1338
1356
if ($ httpstatus === 200 ) {
1339
- $ parsed = json_decode ($ reply, false , 512 , JSON_BIGINT_AS_STRING );
1357
+ $ parsed = $ this -> _json_decode ($ reply );
1340
1358
self ::setBearerToken ($ parsed ->access_token );
1341
1359
}
1342
1360
break ;
@@ -2232,7 +2250,7 @@ protected function _appendHttpStatusAndRate($reply, $httpstatus, $rate)
2232
2250
$ reply ->rate = $ rate ;
2233
2251
break ;
2234
2252
case CODEBIRD_RETURNFORMAT_JSON :
2235
- $ reply = json_decode ($ reply );
2253
+ $ reply = $ this -> _json_decode ($ reply );
2236
2254
$ reply ->httpstatus = $ httpstatus ;
2237
2255
$ reply ->rate = $ rate ;
2238
2256
$ reply = json_encode ($ reply );
@@ -2566,7 +2584,7 @@ protected function _parseApiReply($reply)
2566
2584
return new \stdClass ;
2567
2585
}
2568
2586
}
2569
- if (! $ parsed = json_decode ($ reply , $ need_array, 512 , JSON_BIGINT_AS_STRING )) {
2587
+ if (! $ parsed = $ this -> _json_decode ($ reply , $ need_array )) {
2570
2588
if ($ reply ) {
2571
2589
// assume query format
2572
2590
$ reply = explode ('& ' , $ reply );
0 commit comments