Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130712 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 D26321A00BC for ; Thu, 30 Apr 2026 07:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1777534974; bh=ERifxXDXCtUywfM6C2hf5a8EY5p/6E46ZIcXLfwLpCU=; h=Date:From:To:In-Reply-To:References:Subject:From; b=g94s0cN7v57Eh8nl2kQWtG0VhQJgygDHZIhVfT1JA0FXsAYlmxKeszWff9hI5JJ3u acc4eku0b26b84AexpynlBzsdZhthHrmwzoWN3c33wVK9TfnrfCuUhk76dINlXXEdz 93BwpVOctFzXsSniUXCYVO8plDTx4jSYADfxUWrl+2boLJujSmURBCk+lcX/QDxDwI lm6I6Lirx8hDSbEAPet/65ST3xAJ8eCi8ABFQF/U93MplKG5Oj1Ilp961Ig6GQYBqC wcfb97eSdXzBlethO0LOHJYJxXJKztQRwsjF1Mwvr2I5RG9ei+Qc4spGeRhIVmkIrR bMk1QrkrST1Fw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 622AC180032 for ; Thu, 30 Apr 2026 07:42:53 +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=-0.1 required=5.0 tests=BAYES_50,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: No X-Envelope-From: Received: from fout-a3-smtp.messagingengine.com (fout-a3-smtp.messagingengine.com [103.168.172.146]) (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, 30 Apr 2026 07:42:53 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id 95CE0EC0123 for ; Thu, 30 Apr 2026 03:42:47 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-12.internal (MEProxy); Thu, 30 Apr 2026 03:42:47 -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=fm3; t=1777534967; x=1777621367; bh=T3fXY6i3it xNM+Pl/5sUXgHjCiZ9k1T+ZibqrxKfQ2Q=; b=ezj4YHZJQs3K+r+5g7AWAi7dEz spLX240lHiIQbMB8mU8jVgXmzGtGE5czRc9f2GL7rt039emrYs9Ec0rMXLKrHAeA EILVIFs08p7UYeQ0aRtZ30JorwXdDdLdRKzHv1glmfybRD+qmHU94HQi3FOkDhFN bJeMdxKeCrNzTHY5fc8TjB5CvIGW5cLK4j1Pe7gHwS1QaZ58DWtSOWjf9eF3JTmM ECWkVJoq/7FfY2F6ZD+PFLCg0yWwEnxdd3yOmGtohbobEa5qHQac/5/heoBZaHi0 fLgbb9WqvRjCltjqJvS5L3yQxg5+pNPBTnZ+6l4MDGswOvT6rxzljNGrCKCQ== 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=fm2; t= 1777534967; x=1777621367; bh=T3fXY6i3itxNM+Pl/5sUXgHjCiZ9k1T+Zib qrxKfQ2Q=; b=LvOmh2KMRjhgFVUK6qOmi6CIFnqApRxnCye9KTnOQdr9jv+OVi2 wkBNse6nuiSvLkkjICUu4UR1ESDOjRgkxRMjWnk+MBJzV5BxOSGuW6ZywvpXm0bc EI3BYcTqttNT5I28ZgKxd/0xVctFsfW5e0Flk4zRipgHC9aIKHOMk9OAddxcFU/Q 35FpKs5cu55lS4/zUEWlKod2hBpITa7B63z2E6T7wCpue2zg19Q37AOzpAKCCEZP kIUtbTpYTjOtv7SMuwlbe2cnxOyAOR/+AlBBEHgGbcFtvsii5/apR4RNSbJieOkA 4cmClJZiJpRdQABSr4eJMQkCa0yHHfr/RrQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdekieejhecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepofggfffhvffkjghfufgtsegrtderreertd ejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdr tghouggvsheqnecuggftrfgrthhtvghrnheptdeujedttefhueelhfdtleeiudetlefftd duleehffegtdeihefhleeijefgveegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomheprhhosgessghothhtlhgvugdrtghouggvshdpnhgspghrtg hpthhtohepuddpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepihhnthgvrhhnrghl sheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 5CB47182007A; Thu, 30 Apr 2026 03:42:47 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AJqZv0gpVmjF Date: Thu, 30 Apr 2026 09:42:24 +0200 To: internals@lists.php.net Message-ID: In-Reply-To: References: <4985896b-c80a-4302-912e-9f572a260fb5@app.fastmail.com> <88716CA9-38E4-45CA-9471-2D8928CF4DE2@rwec.co.uk> <3b2b863d-d179-40c9-ad26-8605e854a331@app.fastmail.com> <8ab92f4f-0fce-4239-9732-2d5c7ae1159d@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Context Managers Content-Type: multipart/alternative; boundary=c458bdc5b03265d2ee63b71cd57ff15d211ffa78 From: rob@bottled.codes ("Rob Landers") --c458bdc5b03265d2ee63b71cd57ff15d211ffa78 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Apr 29, 2026, at 17:04, Larry Garfield wrote: > On Wed, Apr 29, 2026, at 9:30 AM, Rob Landers wrote: > > On Wed, Apr 22, 2026, at 20:28, Larry Garfield wrote: > >> I think a key question to answer here is: Do we care to differentia= te between CM errors and underlying errors?=20 > > > > I don't think we need to differentiate at the CM level. Suppression = is=20 > > a policy decision that belongs to the caller, not the context manage= r.=20 > > The CM's job is cleanup: rollback the transaction, close the file,=20 > > release the lock, etc. Whether the exception continues propagating=20 > > after that is the caller's call, and `try using` already provides=20 > > exactly that: > > > > try using ($db->transaction() =3D> $conn) { > > $conn->execute('INSERT INTO orders ...'); > > } catch (ValidationException $e) { > > // Caller chooses to suppress this here > > } > > > > That makes `exitContext()` simple: return void, do your cleanup, and=20 > > get out. If cleanup fails, it throws naturally, and the desugared fo= rm=20 > > can chain the original exception as `$previous` so the root cause is= n't=20 > > lost. If the caller wants to suppress or differentiate, they already=20 > > have `try using` for exactly that. > > > > It's worth noting that every example in the RFC (database transactio= ns,=20 > > file locks, error handler swaps, async scopes) does cleanup and=20 > > propagates. None of them actually need the power to suppress. If a=20 > > context manager wants to give callers a clean exception hierarchy to=20 > > catch against, it can wrap underlying exceptions in their own types=20 > > during cleanup. That's just normal exception design, no special synt= ax=20 > > required. > > > > =E2=80=94 Rob >=20 > Just to make sure I'm following you, you're arguing that a CM should n= ot have any way at all to suppress an exception? I don't think I'd agre= e with that, personally. Even if it's a rare case, I do believe it's a = feature that should remain. I'd argue CMs are mechanisms, not policies. They encode setup and teardo= wn. Suppression is an error-handling policy decision that should be visi= ble at the call site, not mixed with the concerns of setting up and tear= ing down resources. If CM's could suppress arbitrary exceptions, from a developer stepping o= ver the code, they'd see the code randomly appear to jump out of the usi= ng block after a suppressed exception ... at seemingly arbitrary points.= There would be no way to trust what you were reading without having the= CM's code in front of you as well. =E2=80=94 Rob --c458bdc5b03265d2ee63b71cd57ff15d211ffa78 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Wed, Apr = 29, 2026, at 17:04, Larry Garfield wrote:
On Wed, Apr 29, 2026, at 9:30 AM, Rob Landers= wrote:
> On Wed, Apr 22, 2026, at 20:28, Larry Garfield wr= ote:
>> I think a key question to answer here is: Do we = care to differentiate between CM errors and underlying errors? 
>
> I don't think we need to differentiate at the= CM level. Suppression is 
> a policy decision that be= longs to the caller, not the context manager. 
> The C= M's job is cleanup: rollback the transaction, close the file, 
> release the lock, etc. Whether the exception continues propag= ating 
> after that is the caller's call, and `try usi= ng` already provides 
> exactly that:
>
> try using ($db->transaction() =3D> $conn) {
>     $conn->execute('INSERT INTO orders ...= ');
> } catch (ValidationException $e) {
>&nbs= p;    // Caller chooses to suppress this here
&= gt; }
>
> That makes `exitContext()` simple: r= eturn void, do your cleanup, and 
> get out. If cleanu= p fails, it throws naturally, and the desugared form 
>= ; can chain the original exception as `$previous` so the root cause isn'= t 
> lost. If the caller wants to suppress or differen= tiate, they already 
> have `try using` for exactly th= at.
>
> It's worth noting that every example i= n the RFC (database transactions, 
> file locks, error= handler swaps, async scopes) does cleanup and 
> prop= agates. None of them actually need the power to suppress. If a 
> context manager wants to give callers a clean exception hier= archy to 
> catch against, it can wrap underlying exce= ptions in their own types 
> during cleanup. That's ju= st normal exception design, no special syntax 
> requi= red.
>
> =E2=80=94 Rob

Just to make sure I'm following you, you're arguing that a CM should n= ot have any way at all to suppress an exception?  I don't think I'd= agree with that, personally.  Even if it's a rare case, I do belie= ve it's a feature that should remain.

<= div>I'd argue CMs are mechanisms, not policies. They encode setup and te= ardown. Suppression is an error-handling policy decision that should be = visible at the call site, not mixed with the concerns of setting up and = tearing down resources.

If CM's could suppress = arbitrary exceptions, from a developer stepping over the code, they'd se= e the code randomly appear to jump out of the using block after a suppre= ssed exception ... at seemingly arbitrary points. There would be no way = to trust what you were reading without having the CM's code in front of = you as well.

=E2=80=94 Rob
--c458bdc5b03265d2ee63b71cd57ff15d211ffa78--