thecodingmachine / safe

All PHP functions, rewritten to throw exceptions instead of returning false
MIT License
2.37k stars 153 forks source link

Skip `json_last_error` check when `JSON_THROW_ON_ERROR` flag is set in `json_decode` #451

Closed marmichalski closed 4 days ago

marmichalski commented 2 months ago

This handles a rather unpleasant quirk in PHP where if json_decode is called without JSON_THROW_ON_ERROR_FLAG for an invalid json string before calling json_decode for a valid json string with said flag the json_error_last method will report the error from the first call, instead of being reset on the second.

I've implemented a simple test to illustrate how this happens.

https://bugs.php.net/bug.php?id=77997

Also found this: https://github.com/thecodingmachine/safe/issues/437#issuecomment-2139132472

staabm commented 4 days ago

thank you