Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122328 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72315 invoked from network); 7 Feb 2024 14:38:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Feb 2024 14:38:05 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1707316737; bh=YUo6O2/KmH0edLG1Fh8Fh9u5aTFLC8eplfBkf25WLDo=; h=In-Reply-To:References:Date:From:To:Subject:From; b=bIxvkl1WAijlX2MRQ6o90nJ+GEp1+Tdj7/QcK237dc9D5RkomTbUTgIy/IUceAPD9 nuw1dt0D10IDFQn/UTNTQbMeXTcFIkgZsj1RxLkzGYcucS/qxB7Jmt8NiwqnkcHCMc HeN+7LolrgSUWt5YcKAkL26ueTsuJqj485+QawAs9TI8PQocVeSNPpcpHFENhb7TSF y+oIRACBa9X3np92XdvDwltc6bTQTX497uK88PUHRjCeNsgHkKyUwr5nxtHqGvL0pP iXVtW2WibXEPW6RA5ZwVqFwSCtPxLLy5jwzYHgBbKonbObGraJt24+N7LeN1o5FO8Q xjaPDNN3cFwew== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 970F6180061 for ; Wed, 7 Feb 2024 06:38:56 -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=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (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 ; Wed, 7 Feb 2024 06:38:56 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 143AA320034E for ; Wed, 7 Feb 2024 09:38:01 -0500 (EST) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Wed, 07 Feb 2024 09:38:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=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=1707316681; x= 1707403081; bh=eGTDxjPqJejB4UNv2zoeyxxc4WXI5Wy2xK6Lg0hsJXI=; b=M dl0HEE9lGC5e1zuRfBh6bBDpEVn+dteAjJIzXoCb7qHW/iytEyYJF9q3Kus7I+Rm OdO+R8EMiqkkYas2HVUayJ3U5dQaajFhmwpAXaQbkcAYAizM7rWvDtjJjZLx8TCJ EQjx29iu+iupPffuV0bftSnMlfpm0OKo419adngMRfKtJ9891RYjXlkBlMo6oufO 9/wc4G5fkrprs3gIRAMkdTXS5yW97F66fFBF72NlGAW7/G8a/Z+87y5rGlP0tiFK 4Rfb86ubSFM4ZYTheR7nNaKBQHSmAspx3WbWZBqU0KqpuGTvYN1/+zZIPlZ3KoO/ ADBePqfkfoMibyOgFvLDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1707316681; x=1707403081; bh=eGTDxjPqJejB4UNv2zoeyxxc4WXI 5Wy2xK6Lg0hsJXI=; b=dndrkiYqZSDgX7fWFZIknrrxXoc4HLU2iQgi+8Ijwsuy NldsR4DKpKi6pmOwHpFr4xmmEHC7aCA7gSLqvtWiqJ6zq7Zz3oJTk3zQbns9Rwhy sLljWtsiPF0lfXocZgOw1VSaIr6i7qRuIZ+jRRuN85+hoKhY7th7SdTl5jf6Zmjh uixpvPIZy+99Iq/kdQtMOaZh6964YnG1la1pUNuuRjuoU10NtJW6ce8BoOWsyO2S +zr94ren7Q8sjqlJi6a0drq8v/flPxzUF0lcxYdR/eCpmEExRo8/KWnJGDgwde+Z 6yrmMUpFYG923Dm6KwrPd8RXoFhOT1wIcNBwL3CQoQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrtddvgdeigecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnhepkeetleehffegfedvudefueejkefhvddtueeuvdevteei veehledugeejudfhhfetnecuffhomhgrihhnpehgihhthhhusgdrtghomhenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghr fhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 3C6881700093; Wed, 7 Feb 2024 09:38:01 -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: <4fa06ed3-855a-4952-a1fe-c97c5249b814@app.fastmail.com> In-Reply-To: References: <742f202d-7990-4f51-b903-7a15e3fd33c2@app.fastmail.com> <3db4fbe0-22f4-44e2-a1a6-6cd85287df56@app.fastmail.com> Date: Wed, 07 Feb 2024 14:37:39 +0000 To: "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 Wed, Feb 7, 2024, at 10:21 AM, Robert Landers wrote: >> I think there's a subtle but important difference here between what you're describing as the problem and what you implied the solution was (which I then ran with). >> >> What you're talking about is trying to change the error handling model of existing code without changing function signatures. There are only two possible ways to do that, both of them bad: Unchecked exceptions and globals. >> >> What I described, based on the syntax you offered, is checked exceptions, which necessarily means changing the function signature. Error handling is part of the contract of a function. If its error handling changes, it *should* have a signature change to indicate that. (That unchecked exceptions do not do that is the problem with unchecked exceptions.) So if "no changes to existing code" is the goal, checked exceptions as I describe them are not the answer you are looking for. >> >> It seems from your latest message that you're describing more a generalized version of `json_last_error()` and similar functions. The problem there is that such an API design is generally considered very poor practice outside of C, because it's all necessarily based on globals and "hope you remembered to check the thing that no one told you to check and is not even slightly obvious to check". That is not something I would want better support for in the language at all. There's probably cleaner ways to emulate it in user-space, but that is for a particular application to sort out. There's definitely cleaner monadic solutions (which I've written before and are quite neat) using a writer/logger monad, but that again doesn't meet your "don't change existing code" requirement. I don't think anything the language can do will meet that requirement and be a good design. >> >> --Larry Garfield > > Oh wow, this conversation got really interesting while I was asleep :D > > I think this could actually be interesting in a > semi-backwards-compatible way, by just adding some syntax sugar: > > function getResult(): ?Result, ?ResultError { > if($error) return null, $error; > } > > instead of, but this would still work when destructuring: > > function getResult(): array { > if($error) return [null, $error); > } > > This would still work (the "backwards compatible" part): > > [$result, $error] = getResult(); > > or this: > > $result, $error = getResult(); > > Essentially, return types with a comma are just a "strongly typed > array" and a comma on the left-hand side of assignment is just a > destructure. What you're describing here is basically porting Go multi-returns to PHP. That is also an option, though I would probably not be in favor of it. For one, it doesn't really offer much beyond the union returns we already have. For two, it seems like it would necessitate nullable returns for both parts, which is a hard-no from me on type safety. It's going to confuse static analyzers badly. For three, the necessary idioms around Go's error handling are legendarily the butt of jokes. a, err := step_one() if (err) { return err } b, err := step_two(a) if (err) { return err } c, err := step_two(a, b) if (err) { return err } And so on. It's checked exceptions without the ergonomics. :-) --Larry Garfield