Re: What type of Exception to use for unserialize() failure?
| From: | Tim Düsterhus | Date: | Mon, 01 Aug 2022 17:24:47 +0000 |
| Subject: | Re: What type of Exception to use for unserialize() failure? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-118338@lists.php.net to get a copy of this message | ||
Hi
On 8/1/22 14:58, G. P. B. wrote:
Which effectively translates into "don't catch(Error)". No rule without exception :-) In my userland code I also have some blanket catch(Throwable) around *generic* code (i.e. arbitrary callables that can throw whatever type of throwable).During review cmb noted that using an 'Error' here might not be the best choice, as while it is likely to be a programmer error if unserializing fails, we do not want to educate users to catch(Error).I probably have a very different philosophy on this as I don't mind users catching Errors, but it probably be mostly done by Framework/libraries doing some funky stuff.
I've already made those changes (i.e. Exception + ext/date wording). Feel free to add your approval if you agree: https://github.com/php/php-src/pull/9185 --- For the other bits and pieces of your reply I don't have a strong opinion and I'm happy with whatever results comes out of it. Best regards Tim DüsterhusMy suggested path forward would be: For 8.2: - Update ext/random to use the ext/date wording (I like that one best): "Invalid serialization data for <classname> object." - Revert the change from Exception to Error in my ext/random PR #9185.Those make sense to me