-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reset JSON_G(error_code) after calls with JSON_THROW_ON_ERROR #10166
Comments
I think the current behaviour is correct and not a bug "Returns the last error (if any) occurred during the last JSON encoding/decoding, which did not specify JSON_THROW_ON_ERROR." So it looks at the last one which did not use that particular flag. |
Closing per @nielsdos' comment above. |
Thanks for replying! The json_decode/encode is encapsulated by third-party libraries on PHP's eco-systems; for example, guzzlehttp and its dependent libraries of it. |
Okay, changing to feature request. What do you think about resetting |
So this is basically duplicate of https://bugs.php.net/bug.php?id=77997 but we prefer GH issues now so I will leave both issues open. You can also read some discussion about this in https://externals.io/message/105653 and also in the original PR: #2662 . TLDR is that both approaches have their pros and cons and we are not going to change the default behaviour - at least not likely as it would be a BC break. We could however introduce a special flag for those that want to also set |
@bukka In any case, I can reset |
Current behavior is weird and inconsistent with other extensions e.g. mysqli will set @m3m0r7 In worst case you can call |
@KapitanOczywisty |
This really is quite strange behavior that we've just stumbled upon, too. It was exposed to us by having a mix of vendor code running json_decode on invalid string and not caring about the error, and our code later using thecodingmachine/safe in combination with JSON_THROW_ON_ERROR flag (kinda unnecessary tbh), which has led to thecodingmachine/safe#451
I would be interested in what is/are the pros of current behavior? |
@marmichalski I think you're gonna have more luck asking on the mailing list as not a lot of people check the issue tracker actively in comparison to the mailing list. I guess the main compliant here would be BC behaviour. |
Tentatively marking as needs RFC. |
There has not been any recent activity in this feature request. It will automatically be closed in 14 days if no further action is taken. Please see https://github.com/probot/stale#is-closing-stale-issues-really-a-good-idea to understand why we auto-close stale feature requests. |
Description
The following code:
Resulted in this output:
But I expected this output instead:
In json.c file, the function calls
JSON_G(error_code) = error_code
when I turn off flags of JSON_THROW_ON_ERROR.but when I turn on flags of JSON_THROW_ON_ERROR, and then
JSON_G(error_code) = error_code
is not called probably.PHP Version
PHP 8.1
Operating System
mac
The text was updated successfully, but these errors were encountered: