Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128329 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 lists.php.net (Postfix) with ESMTPS id CCB061A00BC for ; Thu, 31 Jul 2025 07:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753945746; bh=rQkIbY9fxAX3eWXyIjdzJectStJuEMZAszZrTpqV1uA=; h=Date:From:To:In-Reply-To:References:Subject:From; b=URKvmxvD/9wwFs8Jw7bIUmLsgxabktuMcv2XKHaEZPrkZlk5ar+snq3/lNJtmeNQj bkluty6yoE4o6U+sBBFnr5qUXEq/L4Op2wUhZJVZ036GjfgSiMXaB6vhYqY6mRnvX0 +WXPG8k2v3wcpKhSzXXSWqeCFIqI1V0LAumBlGeDmhDPkitdEofS/huDUma6dy0fG0 E0l0smqDelGb6uiXTUjKuelkUjWd4t7UUcg4WXiw593kpnvhy74Pie9sHhcO+xlc9X Rnwxl58+eOX6PFkW5sd5xOIj7eIPyImultMcWhiiq4z17knzYJs4tpfClnHpVcP9ix pTEi6n1SAdLWg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 707D9180082 for ; Thu, 31 Jul 2025 07:09:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (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 ; Thu, 31 Jul 2025 07:09:05 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 7D870EC19D9 for ; Thu, 31 Jul 2025 03:10:46 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-05.internal (MEProxy); Thu, 31 Jul 2025 03:10:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; 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=fm1; t=1753945846; x=1754032246; bh=H1af6XtVvk wFyLTzphsvmmz3L2wmxDJRQwppWJvtG1g=; b=DnSrNhBrpLogqoIJ0QN03pOz7S 9VnXLmoVxIyoY1QuqkBp8DMIWzJsvYtUvCkzKnQcI2TiwOoBaOU/Penpq6iLqtfA BSBcxZ3jP3paIKvcBsrHS375rxnQ5KgIO6B0DJNp+GhwC+2bpcQQAE7HQPfx4BTV sJSwnfbvBMnMCOFKhFG2YTZsRPbeAw6ZM9cohk4itTIsZkKk+3ZJe++YWY/BldTm 7QyQVwee96kWvnabi+EqgzfMp4VCllQD+Gd01+m4+2QAqsKpGkyODycOywAogNhX 5MwfGg0iF9uFPO6kxeXmONR6tN+5p2oAGhKx+zgiX0tTTmJsmTIF9grb956A== 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-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1753945846; x=1754032246; bh=H1af6XtVvkwFyLTzphsvmmz3L2wmxDJRQwp pWJvtG1g=; b=Sh+KI96mjd9y0Kah0oYEFIV57t0guAx9Ym8jSOazVdZ4yYucMQl vrS2iOqRMh8OyEgN2q83xLEWayIzvTcXM2hOGAtDvH3QN84dzDPySKkp562l6mKb ybdH8w0nke3pWP1ms7g//GBmZzbskRnect6Cda8DvxGkg2HmjrCi2ob7yjw5dtlB Y1Sf5wxS3kb8ZlmRuew3ECMXixSs7B5pE3s0/loHWqDdPv06jYTSJAkeovN0cBX3 oTWTtW9ei7q3/n89SphPttTlv7/xBCVq5cQn7Yu+d1dQ9qWuQyA0ugQbLlSW11Y+ tEbSl9hJbiuCtlHWm9/HgxXGlrOAu4E2wkA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddutddtudekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucenucfjughrpefoggffhffvkfgjfhfutgesrgdtreerre dtjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggu rdgtohguvghsqeenucggtffrrghtthgvrhhnpedtueejtdethfeulefhtdelieduteelff dtudelheffgedtieehhfelieejgfevgeenucevlhhushhtvghrufhiiigvpedtnecurfgr rhgrmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprh gtphhtthhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgr lhhssehlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 3782F1820074; Thu, 31 Jul 2025 03:10:46 -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: AzoCpASj9aCJ Date: Thu, 31 Jul 2025 09:10:18 +0200 To: internals@lists.php.net Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] Optional Catch Block Body Content-Type: multipart/alternative; boundary=8922c8130f3b4df58c889d33600806b7 From: rob@bottled.codes ("Rob Landers") --8922c8130f3b4df58c889d33600806b7 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Jul 31, 2025, at 06:53, Mihail Liahimov wrote: > Introduction >=20 > Currently, PHP requires a block body for catch clauses even when the c= aught exception is not used. This results in unnecessary boilerplate cod= e. This RFC proposes allowing catch clauses without a body when the exce= ption variable is omitted. >=20 > Proposal >=20 > Allow the following syntax where the curly braces can be omitted when = no exception variable is specified and no handling is needed: >=20 > try { > // code that may throw > } catch (SomeError); >=20 > This would be equivalent to: >=20 > try { > // code that may throw > } catch (SomeError) {} >=20 > Motivation >=20 > Reduced Boilerplate: Eliminates unnecessary empty blocks when exceptio= ns only need to be caught and ignored. > Improved Readability: Makes the code more concise and focuses on the i= mportant parts. >=20 > Backward Incompatible Changes >=20 > None. This is purely an additive change to the syntax. I can see something like this being useful in niche applications. For ex= ample, I have a proxy generation class that creates something like this: public function remoteCall() { $this->operation =3D nameof($this->remoteCall(...)); $this->arguments =3D func_get_args(); throw new SpecialException(); } This SpecialException gets caught to let me know the application has con= sumed the one-use proxy. Using it looks something like=20 rpc(fn(RemoteObject $o) =3D> $o->remoteCall()); which just provides type-safe rpc at the expense of some boilerplate. I also use empty exceptions to "jump" the stack when my framework knows = there is nothing more to do until outside events happen. I think I could= probably use fibers to do the same, but if the user is using a fiber li= brary; there is no guarantee they'll play nice together. This is true wi= th exceptions as well, but the user has direct control over exceptions (= do not catch Throwable, for instance). That being said, I'm doing niche things. Outside of this framework/SDK, = I have not ever really used empty catches, and even in my case, my empty= catches have lengthy comments describing why they are empty in case a u= ser steps into it, so they can better understand how the framework works. =E2=80=94 Rob --8922c8130f3b4df58c889d33600806b7 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Thu, Jul = 31, 2025, at 06:53, Mihail Liahimov wrote:
Introduction

=
Currently, PHP requires a block body for catch clauses even w= hen the caught exception is not used. This results in unnecessary boiler= plate code. This RFC proposes allowing catch clauses without a body when= the exception variable is omitted.

Proposal

Allow the following syntax where the curly braces= can be omitted when no exception variable is specified and no handling = is needed:

try {
    // cod= e that may throw
} catch (SomeError);

This would be equivalent to:

try {
&= nbsp;   // code that may throw
} catch (SomeError) {}

Motivation

Reduced Boiler= plate: Eliminates unnecessary empty blocks when exceptions only need to = be caught and ignored.
Improved Readability: Makes the code mo= re concise and focuses on the important parts.

= Backward Incompatible Changes

None. This is pur= ely an additive change to the syntax.

<= /div>
I can see something like this being useful in niche applicatio= ns. For example, I have a proxy generation class that creates something = like this:

public function remoteCall() {
=
  $this->operation =3D nameof($this->remoteCall(...));
  $this->arguments =3D func_get_args();
 = ; throw new SpecialException();
}

Thi= s SpecialException gets caught to let me know the application has consum= ed the one-use proxy. Using it looks something like

rpc(fn(RemoteObject $o) =3D> $o->remoteCall());
which just provides type-safe rpc at the expense of some bo= ilerplate.

I also use empty exceptions to "jump= " the stack when my framework knows there is nothing more to do until ou= tside events happen. I think I could probably use fibers to do the same,= but if the user is using a fiber library; there is no guarantee they'll= play nice together. This is true with exceptions as well, but the user = has direct control over exceptions (do not catch Throwable, for instance= ).

That being said, I'm doing niche things. Out= side of this framework/SDK, I have not ever really used empty catches, a= nd even in my case, my empty catches have lengthy comments describing wh= y they are empty in case a user steps into it, so they can better unders= tand how the framework works.

=E2=80=94 Rob
--8922c8130f3b4df58c889d33600806b7--