Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118122 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82551 invoked from network); 29 Jun 2022 14:47:40 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Jun 2022 14:47:40 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 53CEF180538 for ; Wed, 29 Jun 2022 09:38:57 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-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,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 29 Jun 2022 09:38:56 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 4FB2F5C05FF for ; Wed, 29 Jun 2022 12:38:55 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Wed, 29 Jun 2022 12:38:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1656520735; x= 1656607135; bh=p1OJhaQqIk3c3Rwi1mXUNhK5tyeAwhVej25ART/ksv8=; b=R 0llYCeEwpWL3jT73yDeqaC3IzGjgwqZNR8cZc8fzM2j5xVaS7dpqBH1wlG4Cmpls ZPN6Gpcigmj8Il7g40bySfM6Ybw2GPvf3OQWS1FCO3iBxvl6LYO2X9MrshJiyI4O t1NOZ4yIX0ePZth51DC35F7nj93ZI8vnOTI4KIWlYr0Dk0xuSo30x1HIVOk6eSGq nhn+H2ExGUT72aBBKS3IBO4yRY2gxaNwzMzCS/c4QB3MkjcTPL49QRMrT/eJmPFZ iIX4ehnJvpFgN2H7iiDo+Qsd0jS45Zo/O3IrkYuqCpIgD1eJC5JwngteI66yNNb9 6eWn3zIWG6WkiuDFZIjgg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1656520735; x=1656607135; bh=p1OJhaQqIk3c3Rwi1mXUNhK5tyeA whVej25ART/ksv8=; b=LIktoYnH7htETH64TgIMefx6iBWmUk7YKTEEq7B3RgWv 330a6E7z4NwmhdMQi4FN0bUmW1H0NrAIvRoOs74p6uvtTQsHZEqgSIF0z2Oq/ZVn 3yTfTlfYGTso2wF/5Vz2/NchQRLHH7otdx7oB/FOV4iUbeJtm9ecBiFV44skm38K RHZo/KEJwXGam49u0kk7LdZiTiksld+zvS4N8PuzbSuIejmHllbR1A+BHl37krB3 nQt/OYrSWCuNRBhaHXPzJd8GcakbI+bqyojcx8XHlQHgv4l7JJ247+OLVc4exCpU +fXx4zwsrNF5wLngP0ETQmEkDf+AtOwKNuIsmhJ6+Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrudegledguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhephfeivefghfffvdduieefffeuveeffeekjeefieef vdfggeekudelfefgueekheelnecuffhomhgrihhnpehgihhthhhusgdrtghomhdpvgigth gvrhhnrghlshdrihhopdhphhhprdhnvghtpdhjohgvughufhhfhigslhhoghdrtghomhen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrh ihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 08ED3170007E; Wed, 29 Jun 2022 12:38:54 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-713-g1f035dc716-fm-20220617.001-g1f035dc7 Mime-Version: 1.0 Message-ID: <3a4338fc-5767-4b1d-a584-95e2ecb82572@www.fastmail.com> In-Reply-To: References: <982FFD13-6B2C-4A28-8091-886F2F637B86@me.com> Date: Wed, 29 Jun 2022 11:38:34 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] Exception type hint From: larry@garfieldtech.com ("Larry Garfield") On Wed, Jun 29, 2022, at 10:42 AM, Guilliam Xavier wrote: > Hi (note: your message was flagged as spam), > >> https://github.com/php/php-src/issues/8843 > > So I understand it as having a "true code" equivalent for the > `@throws` phpDoc comment (similar to type declarations for `@param` > and `@return`)? which would also be checked at run-time? > > Just my 2 cents on that (let's call it "exception specification"): > > 1. IMHO, it shouldn't be mixed in the return type declaration (with > a union-like syntax) but separated and independent (e.g. with a > `throws` keyword, and pipes [or commas] between multiple exception > classes) > 2. AFAIK, Java has it (mandatory to compile for "checked > exceptions", sometimes controversial), C++ used to have it > (runtime-checked) but dropped it (and introduced `noexcept` instead); > I don't know of any dynamic language that has it > > You would also need to define how it plays with inheritance (and > reflection), and what exactly should happen when a function throws an > exception it didn't "declare"... > > PS: I also found some old feature requests: > - https://externals.io/message/4424 > - https://bugs.php.net/bug.php?id=42251 > - https://bugs.php.net/bug.php?id=62404 > - https://bugs.php.net/bug.php?id=67312 > > Regards, Side Note: Please don't top post. On the subject of checked exceptions, I *highly* recommend this writeup from the lead of the Midori language[1]. It's long, but there's a section specifically on exceptions (no deep link, just search the page for it) that goes into a lot of detail about exceptions, checked exceptions, and the ways in which both fail. It's absolutely worth everyone's time. The summary for the short-timed is that the only way exceptions work, from a reliability standpoint, is if they are 1) Rare and 2) Strictly checked and 3) Have really good syntactic shorthand support. And checked exceptions without the other two are a recipe for hell. Basically, it only works if exceptions become an alternate syntax for an Either monad or Go's multi-return. Since PHP is a long, long way from there, I don't believe checked exceptions would be wise, or even slightly a good idea. Not until/unless it's done as part of a global rethink of error handling that reimagines how exceptions and errors work at a fundamental level. And that couldn't be done in a BC way with the current practice of "I dunno, throw, YOLO" in PHP exceptions, so they'd have to be some other, different channel. We are definitely not ready for that kind of fundamental rethink of how error handling works in PHP. [1] http://joeduffyblog.com/2016/02/07/the-error-model/