Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128321 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 9FD721A00BC for ; Thu, 31 Jul 2025 05:44:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753940542; bh=JP16Cbw0a4Y6cjhayKJqmoN+Ajb+aBRn1dk5GmuDyP4=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=SMqBRlN0zGiEoUjjTNFBg3OgnrwLZs7seQAu5y6qd4kE8YEgmfg5bHVzwAvAIaLjm 17YMa5bk5RKfCZWWTqEIOXRbeBk4tlXAwaq1+TX1H/Oo/rg/uh13ptF1FU0S6Yl/lP smSX78pLbPvJsfvcp4POkBerElotOz5xVdnBhuwlVza2Rw1S06+32wXeG3i0v8U/73 +NM9aC3V0/DbHzXbEucJI+0gfUCUDkDc24PFNCH5r27WHHkSrMGJtMloEzoVSDvI+F PpOktOmL4pBt7jiygZDj9X92fhpvc7KriPhwPnrb5AK9Awps0PuslUfPFEHCTPZV1w cdLvsbbEMcI/Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B5A5518003B for ; Thu, 31 Jul 2025 05:42:20 +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.6 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,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 avril.gn2.hosting (avril.gn2.hosting [84.19.162.247]) (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 05:42:10 +0000 (UTC) Received: from avril.gn2.hosting (localhost [127.0.0.1]) by avril.gn2.hosting (Postfix) with ESMTP id 7C4C31C40C7B; Thu, 31 Jul 2025 07:43:50 +0200 (CEST) Received: from smtpclient.apple (unknown [202.145.6.36]) by avril.gn2.hosting (Postfix) with ESMTPSA id BB4511C4057D; Thu, 31 Jul 2025 07:43:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nicksdot.dev; s=default; t=1753940630; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kN1ijIyDPbflxiCO8wY1L+DtdeEsmPr3FUWOiSdiIAc=; b=ZOueHXcq2EpjKUDUa5svg+ka0Ac1fEhRv06zoWhLHNtTv8BTWiYumnvEWjtuYKwv8lclUv cdJf7cYoGqR103FK/FjEg/KxGQrgc+ds6z+NKbR7hlMXV52NeHqKBwV3nhqhMs1F90VDV5 QINRXx4PcJtaFMzCURx40mHlBat9iaXDWy8MsR/V/onW+8kSMp2gxv5WtW3zm6lK7mJkGq JF2mjBpinLBKeFszj704OcGDi1HJJwvQKsiiHif/zBf2BEQzNRSg48NPQznItejPNhKKF/ JpZFCCj5B2a0Z30zH2Y19HUAwIsjk8iXNgy3IQQTzdoIf+++4qOdDyOUIPSOvA== Message-ID: <26D77653-F0F6-4156-ADBA-86D9955C45B8@nicksdot.dev> Content-Type: multipart/alternative; boundary="Apple-Mail=_C3F2C93F-DEF8-419D-A466-5EA29AFC38D4" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.600.51.1.1\)) Subject: Re: [PHP-DEV] [RFC] Optional Catch Block Body Date: Thu, 31 Jul 2025 12:43:34 +0700 In-Reply-To: Cc: PHP internals To: Mihail Liahimov <91liahim@gmail.com> References: X-Mailer: Apple Mail (2.3826.600.51.1.1) From: php@nicksdot.dev (Nick) --Apple-Mail=_C3F2C93F-DEF8-419D-A466-5EA29AFC38D4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 31. Jul 2025, at 11:53, Mihail Liahimov <91liahim@gmail.com> wrote: >=20 > Introduction >=20 > Currently, PHP requires a block body for catch clauses even when the = caught exception is not used. This results in unnecessary boilerplate = code. This RFC proposes allowing catch clauses without a body when the = exception 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 = exceptions only need to be caught and ignored. > Improved Readability: Makes the code more concise and focuses on the = important parts. >=20 > Backward Incompatible Changes >=20 > None. This is purely an additive change to the syntax. >=20 Hey Mihail, Why would the `catch (SomeError)` still be required if it isn=E2=80=99t = used? Cheers, Nick= --Apple-Mail=_C3F2C93F-DEF8-419D-A466-5EA29AFC38D4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On 31. Jul 2025, at 11:53, Mihail Liahimov = <91liahim@gmail.com> wrote:

Introduction

Currently, PHP requires a block body for = catch clauses even when the caught exception is not used. This results = in unnecessary boilerplate 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 {
    // code that may = throw
} catch (SomeError);

This would be equivalent = to:

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

Motivation

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

Backward Incompatible = Changes

None. This is purely an additive change to the = syntax.


Hey = Mihail,

Why would the `catch (SomeError)` still = be required if it isn=E2=80=99t = used?

Cheers,
Nick
<= /html>= --Apple-Mail=_C3F2C93F-DEF8-419D-A466-5EA29AFC38D4--