json - How do I ignore PHP Notice: json_decode(): integer overflow detected in Yii? -
i'm trying decode long integer in json, crashes , gives error in yii. use json_bigint_as_string
option. how bypass error or ignore it?
php > var_dump( json_decode('[66933258,"b009gq034c",281441845828]', false, 512, json_bigint_as_string)); php notice: json_decode(): integer overflow detected in php shell code on line 1 array(3) { [0]=> int(66933258) [1]=> string(10) "b009gq034c" [2]=> string(19) "9223372036854775807" }
in app, gives
php notice – yii\base\errorexception json_decode(): integer overflow detected
just tried code , on machine works perfectly, perhaps has php version or so?
the thing can think of (if don't need values number, values) use preg_replace
"escape" numbers strings first:
$json = '[66933258,"b009gq034c",281441845828]'; var_dump(json_decode(preg_replace('/(\w)(\d+)(\w)/', '\\1"\\2"\\3', $json)));
will yield this:
array (size=3) 0 => string '66933258' (length=8) 1 => string 'b009gq034c' (length=10) 2 => string '281441845828' (length=12)
edit:
now i'm looking bit closer: getting value on command line. json_bigint_as_string
working correctly. problem json_decode()
-function seems generate notice before switches behavior. yii's error handler captures notices default , converts them exception.
in case solution might simple as:
var_dump(@json_decode('[66933258,"b009gq034c",281441845828]', false, 512, json_bigint_as_string));
i advise against using silence operator because obscures errors, in case beats alternative (disabling capturing notices , possibly missing other errors)
Comments
Post a Comment