Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119057 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 5920 invoked from network); 30 Nov 2022 09:26:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Nov 2022 09:26:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 483901804A9 for ; Wed, 30 Nov 2022 01:26:57 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_NEUTRAL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS30827 82.113.144.0/20 X-Spam-Virus: No X-Envelope-From: Received: from xdebug.org (xdebug.org [82.113.146.227]) by php-smtp4.php.net (Postfix) with ESMTP for ; Wed, 30 Nov 2022 01:26:56 -0800 (PST) Received: from localhost (localhost [IPv6:::1]) by xdebug.org (Postfix) with ESMTPS id 9C72A10C02C; Wed, 30 Nov 2022 09:26:55 +0000 (GMT) Date: Wed, 30 Nov 2022 09:26:55 +0000 (GMT) X-X-Sender: derick@singlemalt.home.derickrethans.nl To: PHP Internals List , Vincent Langlet , PHP Internals List In-Reply-To: <707E8C39-F471-4C6F-B59C-A0D60D4C663E@php.net> Message-ID: References: <707E8C39-F471-4C6F-B59C-A0D60D4C663E@php.net> User-Agent: Alpine 2.23 (DEB 453 2020-06-18) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Subject: Re: [PHP-DEV] Using less generic exceptions for dates From: derick@php.net (Derick Rethans) On Mon, 21 Nov 2022, Derick Rethans wrote: > On 21 November 2022 11:34:10 GMT, Vincent Langlet wrote: > > > >When using json_encode or json_decode with the `JSON_THROW_ON_ERROR` > >flag, `JsonException` might be thrown. > > > >When using `new DateTime('foo')`, a generic `Exception` is thrown. > >Incidentally, I wonder why it's not an `InvalidArgumentException` > >(but that could be another debate). > > > >But my main point is that I think it would be useful to use a specific > >exception > >``` > >class DateException extends Exception {} > >``` > > > >- It allows a specific treatment when catching exceptions > >- It allows a specific analysis when using static analysis tools > > like Psalm or PHPStan. > > > >In a general way, I would say that PHP class/method should always use > >scoped Exception instead of generics ones. > > > >I know nothing about how php is implemented but I would say > >introducing DateException shouldn't be too hard and it's BC. What do > >you think ? > > I think this is a good idea and will add it to my todo list to > investigate. I have now made an RFC for this: https://wiki.php.net/rfc/datetime-exceptions cheers, Derick -- https://derickrethans.nl | https://xdebug.org | https://dram.io Author of Xdebug. Like it? Consider supporting me: https://xdebug.org/support Host of PHP Internals News: https://phpinternals.news mastodon: @derickr@phpc.social @xdebug@phpc.social twitter: @derickr and @xdebug