Re: json_encode() / json_decode() warnings

From: Date: Thu, 27 Jul 2017 15:57:39 +0000
Subject: Re: json_encode() / json_decode() warnings
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-100062@lists.php.net to get a copy of this message
2017-07-27 17:41 GMT+02:00 Craig Duncan <php@duncanc.co.uk>: > Hi internals, > > When using json_encode() and ÄD > go‘ÖãÔ]ÿeBÚä–json_decode() it is required that you > manually check for errors after every call, eg: > > ```php > $data = json_decode("false"); > if (json_last_error() !== JSON_ERROR_NONE) { > throw new UnexpectedValueException(json_last_error_msg()); > } > ``` > > This isn't _that_ unusual in PHP, however normally in these situations a > warning would be raised. But the JSON functions only raise warnings in a > couple of scenarios, most issues are completely silent. > > I wanted to begin a discussion around changing this, so that warnings are > raised for any issues during json_encode() and ‡�6=!V×ír_)ºþ > ¥json_decode(). > > I have an implementation ready and I'm happy to draft an RFC if this > suggestion doesn't receive universal hatred. > It should rather just throw exceptions. Warnings do not really allow error handling, they just allow error reporting. Regards, Niklas

« previous php.internals (#100062) next »