Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122314 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10922 invoked from network); 6 Feb 2024 20:09:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Feb 2024 20:09:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1707250207; bh=wy+8tTpwVr0uFoG178nmde3z4/9aUcXd5n3Xr2mMLqI=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=Okhz5BUR6CsqGe+Dtl/Iv5KMAHhdJH/F7N5yPhamc2n6VYFYD1kmJkxa25OGcVGwP yckR5sdyaNnwi4hrzepFBI9B+6KfqPiIfnkRPIn/fpXU4bZ9RTBaFMGggRp4qxoUzA n55Gu2WE5GyRVhJmnufxjZfYpnjOsv3r0L3Nsk0SnauXzkDPWm9kwELbWYQ43KZ1NF 4rdwvWeITSMQfskREvFV3nC3q81xPX0haKIdMJBSRpgQBRazvDTg557cuPHeELVNAW hj3z//RAuVQOBJS2GmRBzYDrWoI0HzXZQM6oBJ1w6vq1vJkFMdPGvboJTfJHyn14hy 4a2Wuow2nNWEw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0BD83180039 for ; Tue, 6 Feb 2024 12:10:06 -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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 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:10:05 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id B0B075C00F4; Tue, 6 Feb 2024 15:09:12 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Tue, 06 Feb 2024 15:09:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:cc:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1707250152; x=1707336552; bh=LKaqg2HdSvgcwJzFqFAKcELOPQsB6nFyHiSTJbyJKp8=; b= kvUu9rlUhMRC5FNNd6UdsPPf26+u9Y9yKOXcQdwh36Gt+Wyub+NGLyQYVOgibsp5 UgOsx01AdAReBp2+9NiU43DwI/L2fm8PSThhWH/z9UTmOYMM58YsLCFbD7tNcXCr /oGgOW5EyKizxKkSqmyypWt82oLqE2Tht0KrWSZ/UR0e5Ey1NCG+S9o9w9/IIhMk OEceZVACHJbVkynHSR3QziTcuIEc60Z1Pm3qucPbxwSSZ6qzkryJFuqRYmIyD7Mi smBk+SLHFtnWqwS+mptDEK+ThnyGskL/vzZPa1Ml4S7gGgfjUa+oZrl90LWmoDp0 Ub9kw0AK0BByTZ6Ejz36tA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1707250152; x=1707336552; bh=LKaqg2HdSvgcwJzFqFAKcELOPQsB 6nFyHiSTJbyJKp8=; b=FekrTh7eiX/eOop5QiOkF0ov+g77PJ7CeApRC9v5jbLx ktsuryCTwVTBgnH22zJYHXlmhS6VfXo5gwYh7Dbd7EtnYPb/6YWV+lsg4WyM2h4P 0puuI7awplkagNZtSLsl/adC6e3LWMh2+Uqmcga7miAR7bCUSmSvE/cN7tgOGJk1 Ci2IAX2p7tnthYNtSDhDGDl/aUZmKOwWxyT/FKhJTq8KfFSS4sCcPfiJDZekKbxZ xfPKmiuYAGXMKftUVe09tHacXfydzR8Yo71w4MmUFPwo303p4sR3ec/m1umRwFYe zAxoZ+OM9U9UUS5ri5DYWS53RMuLQm2b6nN8StBT1A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrtddtgddutdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeeutdduffeglefgleekteeifedvgfffhfeiveff vdfgkefgvedtfedugfeggfdunecuffhomhgrihhnpehphhhprdhnvghtpdhgihhthhhusg drtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 584111700096; Tue, 6 Feb 2024 15:09:12 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-144-ge5821d614e-fm-20240125.002-ge5821d61 MIME-Version: 1.0 Message-ID: In-Reply-To: References: <742f202d-7990-4f51-b903-7a15e3fd33c2@app.fastmail.com> Date: Tue, 06 Feb 2024 20:08:51 +0000 To: "Arvids Godjuks" Cc: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Feature request: https://github.com/php/php-src/issues/13301 From: larry@garfieldtech.com ("Larry Garfield") On Tue, Feb 6, 2024, at 7:18 PM, Arvids Godjuks wrote: >> To be clear: I really like this concept and have discussed it with others >> before, using almost exactly this syntax. I have not proposed it because >> my read of Internals lately is that there's no stomach for more >> type-centric behavior, especially with the obvious "But we already have >> exceptions, what's yer problem?" response (which is valid to a point, but >> also incomplete for reasons explained above). The responses in this thread >> so far confirm that fear, but as an optimist I'd be very happy to be proven >> wrong if there is an appetite for improving error handling via the type >> system. >> >> Absent that, union types and enums (or really any interfaced object) or a >> purpose-built Either object are the best options today, and while they're >> not ideal, they're not bad options either. >> >> None of that logic or argument requires sh*tting on OOP as a concept or >> abusing others on the list, however. Doing that only undermines the valid >> point that there is ample headroom to improve PHP's error handling. >> >> --Larry Garfield >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: https://www.php.net/unsub.php >> >> > Thank you Larry for this interesting summary - didn't remember there was > quite a bit a discussion around the topic prior. > > I lean on the "we have exceptions, just leave it be" side out of practical > reasons - the vast majority of OO code has standardized around the approach > and interoperability is high. It makes using code that's out there super > easy and predictable - almost nobody uses the "return false|0|-1" out there > (at least I haven't used code like that except the PHP's stdlib, and even > that has been changing little by little). It makes error handling > predictable, and considering the type of code we mostly write in PHP - most > of the time we leave the catching to the global top-level handler or > sentry/bugsnag/etc libraries. > Consistency is the word I want to highlight here. For better or for worse - > it's the method the PHP ecosystem arrived at and it's the predominant one. > Introducing a distinctly different method of error handling is going to > bring in wrappers around libraries that convert errors to one style or the > other, the application code can end up using different ways of error > handling, etc, etc. My approach is to grab a different language aka "the > right tool for the job" if I want to build things differently, that's why > we have so many programming languages and not just a few :) > > I'd put resources into optimising the VM and php engine to handle the > exceptions better and if there are improvements to be had there - do those > maybe? (I suspect JIT is also going to influence this a lot going forward). "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: public function find($id): ?Product {} public function find($id): Product { // This is very expensive I don't think will ever not be. // It will also bubble up to the top of the application and crash the whole process, // Or still show up in weird, unexpected places. throw new NotFound(); } public function find($id): Product|RepoError {} enum RepoError { case NotFound; } 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.) --Larry Garfield