Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122319 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18890 invoked from network); 6 Feb 2024 20:39:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Feb 2024 20:39:28 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1707252020; bh=Sm3GqSpBAUDq8Tf+S842/+MK3uj2LbWfWB25GZq3bNc=; h=Date:Subject:To:References:From:In-Reply-To:From; b=lUJZR5I+H2oSk7w8djaOz9YhsK7TRXMHb+1hymxmaJfYekzUiTbIXlRXCrA53ltRO 1530ZS08v7UOFwSe6gGEAM44tUMXkqU1sY59ZbdQHT5AFoXbHk290VcCFBVhs+8qKC PdbUjsMhQYlJKOsok4srqxbt3vbOqOq0fn4B9xwBmwD2ZpI5WvcxMrllGNO5uMSrYs h2r2gJrzWQhgB2AQlMe6vrNPmC7iyJ3TSnsStx3giFgLshV6YhdF2YwaqaoewrFSLP 7/zhvvwKB7/HN4brWSkM1t0Y53HqYo5ZqEjM+XmP1j9FS5kk00wK5CBpOoX64U57ml H5t+4lxLJOMcA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AC168180064 for ; Tue, 6 Feb 2024 12:40:17 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05,DMARC_MISSING, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from chuck.smtp.mailx.hosts.net.nz (chuck.smtp.mailx.hosts.net.nz [43.245.52.157]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 6 Feb 2024 12:40:16 -0800 (PST) Received: from 125-239-41-100-fibre.sparkbb.co.nz ([125.239.41.100] helo=[192.168.1.65]) by chuck.smtp.mailx.hosts.net.nz with esmtpsa authed as varteg.nz (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim 4.96) (envelope-from ) id 1rXSDu-00181D-1J for internals@lists.php.net; Wed, 07 Feb 2024 09:39:18 +1300 Message-ID: <4f175865-1b04-4e1e-a833-e4f463daafbf@varteg.nz> Date: Wed, 7 Feb 2024 09:39:09 +1300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-GB To: internals@lists.php.net References: <742f202d-7990-4f51-b903-7a15e3fd33c2@app.fastmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Hosts-DKIM-Check: none Subject: Re: [PHP-DEV] Feature request: https://github.com/php/php-src/issues/13301 From: weedpacket@varteg.nz (Weedpacket) On 2024-02-07 09:08, Larry Garfield wrote: > > "The right tool for the job" is indeed the strongest argument for lightweight exceptions. It's a tool we lack right now. > > I'm thinking not of "DB went away" type issues (Exceptions are already fine there), but "requested product not found." Right now, the options we have are: > > ... > > The first is probably most common, but null (as I go into in the article) doesn't tell you anything and leads to mismatch errors. > > Exceptions, I'd argue, are just plain wrong in this situation. (Which means, yes, all the frameworks that throw exceptions on route-not-found are doing it wrong.) > > And the union-enum approach is a bit clunky as it has no native language support, and no solid conventions behind it. This is my preferred approach personally today, but I think we can do better. Even just having this available at all means that "well everyone just uses unchecked exceptions" isn't entirely true. (All three of the above can be found in the wild.) > I can add a fourth option for the "get record by ID" that may not be found, that I've seen in the wild: public function find($id): ProductSet {} Where the ProductSet is a collection of (in this case) no more than one Product. It's up to the caller to verify there actually is a Product inside and extract it, and it's also the caller's decision whether not finding one is a problem or not. Of course, in this domain it folded in with using ProductSets to represent more general collections of Products and the resulting set algebra. Weedpacket