safe
safe copied to clipboard
Skip `json_last_error` check when `JSON_THROW_ON_ERROR` flag is set in `json_decode`
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