Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127193 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 6C32D1A00BC for ; Sun, 27 Apr 2025 06:07:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1745733889; bh=+SHHR4KFaU8s+WcPqaBv7kH0I4xCjp0De/baCutN1Og=; h=Date:From:To:In-Reply-To:References:Subject:From; b=L4cTlQ6tCa3c044uerldajPqvxbikcLZl5lC9C/IseqS3CBvBxy+GaaA/NRVA77dp zifxH1NhIx0bsNwbTZ92bPjq45BTY4pG3QHNholCIfCIVCZMJBxzChAUSwCiCopf4W glT/G+SEmqtpM0i2cglj50u0fZYllwS6zVe4TA2xPuG1/JJqjZSvgUlslHwE6mD6nf 0XUdzN1EmSrNFVp++B83LnYGOk73K9MhGpFvUmM4prOUlCbRtJCznsE2aKjlg3lTxB vtABxQt99K0bI55t1Ie0PspiIZDI/iRUYCyQboCIBrQ0ALTyqA9ixwfJMLjDoZ/Ocu 6bLqScS5SWjhQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C3C77180084 for ; Sun, 27 Apr 2025 06:04:48 +0000 (UTC) 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.1 required=5.0 tests=BAYES_50,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: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fhigh-b8-smtp.messagingengine.com (fhigh-b8-smtp.messagingengine.com [202.12.124.159]) (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 ; Sun, 27 Apr 2025 06:04:48 +0000 (UTC) Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfhigh.stl.internal (Postfix) with ESMTP id 9892025401B2 for ; Sun, 27 Apr 2025 02:07:05 -0400 (EDT) Received: from phl-imap-06 ([10.202.2.83]) by phl-compute-10.internal (MEProxy); Sun, 27 Apr 2025 02:07:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding: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=1745734025; x=1745820425; bh=wjHM6L0lh/MpucOe8/ODD dCq86eTJBiKCy8aV5EyZZ4=; b=kEzJnx3BfVCG/PJGscWRJoWkyrwvspBw00Yok 131iyv+4yhuE2xud9VcE+tnVSBxqeSJWy0ZvqqybF061N2pTEOz07dju4Zu0rpGY wAzY2vX+6/VKfSfwsU6Y7saYf40le07c3ZtYjqjuby3efIdBqWOLH4Uo+cPvwCff qpSZoLThnAB60Pu0E0mEgMlsd9lDqBe7qYRlzAfg5gIQNmbOKLvsHNb2XXEhRX0B J4LEA4aYw1qYSNKTuW0TkedsEb05cDlZ9GO/LWvnA5glUk5h3SgpYx0j5k4XuLMF zIxe2zwJnc4lYp7YbhjohZN2JjTFV12rZ4aeNU94f9jF5syNg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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-sender :x-me-sender:x-sasl-enc; s=fm3; t=1745734025; x=1745820425; bh=w jHM6L0lh/MpucOe8/ODDdCq86eTJBiKCy8aV5EyZZ4=; b=BxL9phkz3QEcM/+p7 pAbwMSq5h9+I/YLS92oTcwm1ZnklOClHyGTGSrHgHGJM5YJwACWDCW9toJvb1Ctt 5yVYlvPXQrrnHkaECBRoLw3QuRTo09nFdDqMmwli2yQ3qunZcWg6JefF13LCJ/+a BMU5ZfI5MZtKM8k2eTAtmRnqbaVGBM1yZXh0bNy2uWhpv8YLgC/SNYFNOiX6s/2X yU0Wbqh/s5w0TnIyuC3KuI+JWOlHMsatVABQK2h1YIWFp+zGZeN/v0MsJAvpIyC3 nlvpneG+YE7GSBP+W8vGJMmdxmPgW1te/QsFxifIBJlGW5tfOQmpiRMlLSUaVZ16 Rhd2g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvheejfeduucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtgfesthhqredtredt jeenucfhrhhomhepfdfnrghrrhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrh hfihgvlhguthgvtghhrdgtohhmqeenucggtffrrghtthgvrhhnpeffieeivdfhvdeguddt tdegteeiueegvefhteehfeeffeetudeitdehtdegjeeuieenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlught vggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtg hpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 1F44329C0072; Sun, 27 Apr 2025 02:07:05 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: T7e0f24752af1ea38 Date: Sun, 27 Apr 2025 01:04:49 -0500 To: "php internals" Message-ID: In-Reply-To: <7e923206-139a-4442-824e-895b09d563a2@app.fastmail.com> References: <39597a9c-6854-40c6-a529-32b2b178cb27@app.fastmail.com> <7e923206-139a-4442-824e-895b09d563a2@app.fastmail.com> Subject: Re: [PHP-DEV] Concept: Lightweight error channels Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Sat, Apr 26, 2025, at 11:19 AM, Rob Landers wrote: > Hey Larry, > > I=E2=80=99m still digesting this, but I wonder if this problem (errors= vs=20 > non-world-ending errors vs happy path) is a problem due to people ofte= n=20 > making warnings into exceptions? > > I feel like many devs/frameworks =E2=80=9Cabuse=E2=80=9D (for lack of = a better word)=20 > the error handling system to make everything into a world-ending-error=20 > when it is not.=20 Yes, it's common for devs today to use exceptions in inappropriate ways.= I've done it myself at times. The problem is that we don't have a too= l fit-for-purpose for "your input is invalid in a totally predictable wa= y." So you can either squeeze an error code into the return value (null= or otherwise), which sucks, or abuse exceptions, which sucks. That's e= xactly the issue I want to solve, by offering a tool more purpose built = for that case. > Even over the last few versions of PHP, more and more warnings have=20 > turned into exceptions that maybe ought not be. > > Overall, this has resulted in a somewhat more inconsistent language=20 > than it was previously. For example, you used to be able to consider a= n=20 > array as a field of infinite nulls. You could iterate over an infinite=20 > set of keys and get nothing but null. This made it easier to explain t= o=20 > junior devs at the time. Now, you have to explain it as a=20 > hash-map-but-sometimes-array-thing that emits warnings when a key=20 > doesn=E2=80=99t exist but will still give you null.=20 > > We are currently in this weird place between =E2=80=9Cinfinite field o= f nulls=E2=80=9D=20 > and =E2=80=9Csparse array/hash-map=E2=80=9D but not quite either one =E2= =80=94 depending on=20 > what you do with that warning.=20 Treating arrays as an infinite series of nulls, however... no, that's al= ways been a developer error. If that was the mental model you were work= ing from, it's an incorrect mental model, and it always has been, since = forever. Arguably it's PHP's fault for letting you develop that broken = mental model because it didn't complain loudly; both PHP and MySQL start= ed life with lots of "we'll quietly assume what you probably meant and n= ot tell you that you're wrong" features, and both have had a very long, = very painful process of correcting that fundamental mistake. Anyone wor= king from an "infinite series of nulls" model has been an unfortunate vi= ctim of that design flaw. It's possible we could use light-checked exceptions as a better way of s= ignaling "hey, you're reading an invalid key". So far I've only conside= red them as a function-boundary thing, but we could probably look into r= aising them implicitly for certain read operations. (Maybe only on obje= cts that are using Gina's forthcoming Fetch interfaces? I dunno.) > It would be great if we could pick one and I think it would also solve=20 > the whole =E2=80=9Cis null an error or a value=E2=80=9D problem.=20 Just having an "alternate null" is not viable for many reasons, which I = go into in the article I linked before so I won't repeat it here. > I personally wouldn=E2=80=99t like checked exceptions. I have PTSD fro= m Java=E2=80=99s,=20 > so just hearing that phrase gives me flashbacks of catching dozens of=20 > potential exceptions. In Go, yes there is some boilerplate, but it=E2=80= =99s=20 > not that bad and it easy to deal with, especially with IDE support.=20 As the Midori article I linked explains, the PTSD you have from Java exc= eptions is not an issue with checked exceptions; it's an issue with Java= 's terribly designed exception system, combined with all values being in= herently nullable. A well-designed checked exception system doesn't "force you to handle al= l these error cases". A well-designed system "tells you every error cas= e that you need to think about, and helps you deal with it." Smart usag= e of interfaces on the error values can make dealing with a whole class = of issues easier, and some more ergonomic syntax than try-catch (such as= Rust's ?) can make it less cumbersome. In a sense, checked exceptions show you exactly what you need to do in o= rder to turn a partial function (that just dies on certain values in its= input range) into a total function with two return channels (because yo= u'll always get back a legit value, just sometimes the legit value is on= the error pathway.) That both surfaces the unhappy paths (that any rob= ust code should handle) and simplifies handling them. > As for a Result type, that=E2=80=99s already possible in user-land; wh= at does=20 > bringing it to the engine get us? Is it just a lightweight exception=20 > without a trace to prevent the cost of generation? Why not just have a=20 > pool of exceptions that you can just modify the message? A general purpose Result type requires generics, or else you lose all ty= pe info on what the real return value's type is. We don't have generics= , so that's simply not an option. The separate channel approach gives u= s all the benefits of a Result type without the need for generics, and i= t's standardized in the language. A general purpose Result type is also very clumsy to use in practice, un= less you have syntax optimized for working with it. Rust has its match = statement (which supports pattern matching, decomposition, and multi-lin= e statements specifically for dissecting a Result type) and ? operator, = which is a one-character way to "pass on" the error to the caller, as th= ough it were an unchecked exception. For PHP, we'd probably want a diff= erent set of syntax tools as our working model is different than Rust's.= What those would be, I don't know yet. Hence this thread. --Larry Garfield