-
Notifications
You must be signed in to change notification settings - Fork 20
ErrorException: json_decode(): option JSON_BIGINT_AS_STRING not implemented #28
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This seems to be a bug in PHP 5.5 with the php-json package on Ubuntu, see https://stackoverflow.com/questions/19520487/json-bigint-as-string-removed-in-php-5-5 I'm investigating if I can reproduce and create a workaround for this issue. |
I can send you a test implementation if you'd like it. Let me know if you need any help. |
That would be nice. Or can you test, if this workaround works for you? $input = '{"errors": []}';
if (version_compare(PHP_VERSION, '5.4.0', '>=') && ! (defined('JSON_C_VERSION') && PHP_INT_SIZE > 4))
{
$obj = json_decode($input, false, 512, JSON_BIGINT_AS_STRING);
}
else
{
$max_int_length = strlen((string) PHP_INT_MAX) - 1;
$json_without_bigints = preg_replace('/:\s*(-?\d{'.$max_int_length.',})/', ': "$1"', $input);
$obj = json_decode($json_without_bigints);
} |
The problem is I don't want to use json_decode() directly, I just want to use your package. This workaround works if and only if I want to json_decode() directly if I'm not mistaken. |
I understand. I just wanted to ensure that this workaround works for your issue, so I can put it in the package. |
This workaround will work for me if I you'd encapsulate all your json_decode() calls. |
Great. This is no problem. A fix is on the way. |
Sounds good. Let me know if I can test it. |
There is a bug in the workaround. It cannot handle this situation: $json_string = '
{
"fake_int": ":1234567890123",
"real_int": 1234567890123
}'; So, another workaround would be to only use $json_string = '
{
"fake_int": ":1234567890123",
"real_int": 1234567890123
}';
$options = ( version_compare(PHP_VERSION, '5.4.0', '>=') and ! (defined('JSON_C_VERSION') and PHP_INT_SIZE > 4) ) ? JSON_BIGINT_AS_STRING : 0;
$data = json_decode($json_string, false, 512, $options);
var_dump($data); |
It returns me this:
|
Great. But now I have discovered an issue on my Ubuntu machine which don't parse big integers into strings correctly. 😄 Could you please test the parsing of this big integer $json_string = '{"big_int": 123456789012345678901234567890}';
$options = ( version_compare(PHP_VERSION, '5.4.0', '>=') and ! (defined('JSON_C_VERSION') and PHP_INT_SIZE > 4) ) ? JSON_BIGINT_AS_STRING : 0;
$data = json_decode($json_string, false, 512, $options);
var_dump($data, defined('JSON_C_VERSION'), PHP_INT_SIZE, $options); and give me some information about your CPU (32 or 64 bit) and your PHP version, please? uname -a
php -v |
output of your big integer parsing:
|
Thank you. I have the same (wrong) integer result on my Ubuntu machine and I think this is a bug that JsonApiClient can't fix. I will add the workaround: $options = ( version_compare(PHP_VERSION, '5.4.0', '>=') and ! (defined('JSON_C_VERSION') and PHP_INT_SIZE > 4) ) ? JSON_BIGINT_AS_STRING : 0;
$data = json_decode($json_string, false, 512, $options); But you have to keep in mind that integers bigger than 9223372036854775807 would be interpreted wrong by |
I just released 0.6.3 |
Thank you. Other question. What do you think, which library/PHP module do I need to replace/upgrade in order to get rid of this issue? |
solved the problem. Many thanks for your time.
|
I'm glad I could help. |
Thank you again, let me know if you need any help. I owe you one. 👍 |
I try to consume my own Laravel 5 API JSON response and I got this error message:
ErrorException: json_decode(): option JSON_BIGINT_AS_STRING not implemented
For this JSON output:
{
"errors": [
{
"status": "404",
"source": {
"pointer": "http://localhost/api/v1/this-is-not-exist-for-sure"
},
"title": "The requested resource has not been found",
"detail": "We're sorry, something unthinkable happened"
}
]
}
Did I do anything wrong?
The text was updated successfully, but these errors were encountered: