Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130708 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 1FDD11A00BC for ; Wed, 29 Apr 2026 14:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1777473088; bh=ueEJ36ZwJD38rnOhVjeq/Q1W4ByyLbBcv6i5hchCRqk=; h=Date:From:To:In-Reply-To:References:Subject:From; b=aF+qbMeVe2BmQMrWKTZrY4oxwRIJs0/9I1pAfCv/1UtI+x5yb6s9gMmuu9Zejrrae I7Vq508Ee09krg9wKc7dPB6xTOrS5goiQtKgiUqXceBAeTmZiutpQiDciOLTUUI9fS ulFEAHLFaIoPez+5QhkioPqvJi6CE6LV8OI0kQzQiVxIRsyHvH/Hk6woRPnD5whXuJ SAeG02qTR9tAIf6keCG7P8V92ZJuSufEqHPam3pB8wfstjW5bHKD2UrqP8zhvrJZpJ IFaBMVryX7w4+wLym5wXesELMdRaV+YILbru/9uw0g7M9r8sbG47tGMrSYJGpHoK9R iUfmULnSFiaIA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7EDA5180048 for ; Wed, 29 Apr 2026 14:31:24 +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,T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-a8-smtp.messagingengine.com (fhigh-a8-smtp.messagingengine.com [103.168.172.159]) (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, 29 Apr 2026 14:31:24 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id AD3FF1400010 for ; Wed, 29 Apr 2026 10:31:18 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-12.internal (MEProxy); Wed, 29 Apr 2026 10:31:18 -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=1777473078; x=1777559478; bh=59EnBn7aF7 0HP4iPji377n5qAjS2DP8g+OnQS5HzttM=; b=ZhszoHntWnQVD2HTtmsSM3aAgm 0TUyjFOuHzMeGdJ6Osg5t1gOxb5jTA/imuBu3m6r44cikQmbXaQwrbvPRr4TcqMa XurSgnwlmaXsOnHXO6jrdaHfOXPdqwvhu6a1LJFJz0yrPSSB2ayqX12La9dTMKty kSsub8yshE6yniVYAkqp4Q8GfdLMR1G8B884K/6rA2ug4Ad6rTjPJvIIItcBbdVx rY8bcuyKOpGsQpsKBXIJt3vkOKHE+9D2pUaU0B4cTAs8WMgWxKFhgGigDSx9cVi1 tnTsGMMbR99NlE7wI0CkBcfU0mCQGG4xGtV2bnPlyse1fsmrU5m/6Ke4SgUQ== 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= 1777473078; x=1777559478; bh=59EnBn7aF70HP4iPji377n5qAjS2DP8g+On QS5HzttM=; b=b6peExiPtfWFIoTHQ9qzUTsv3MQX4GsdBP4YeweCIhU5Q6I+mid 21cxrV0IxjZOvAVFT1KvGbyyYT0HC5brKVOOhXvhhXQZTG0thwk8x15jw61e9aUW 8c34xYgF+L/o0v1KGMfb9Z1NvUciZ8BNwsGFrKbtxZTJjZQVK28fwC1yamB5wbdd w9JJahkA9OFi5b2StFEEfLiR4WYRyGxT85acnM3rorqkRHeRbJGHVCqqSMQyuDsH 9W39+42pd60zzBCIvC2hi5CoEnOwLl2MT8Tt546NU5CCRCwpkPb9R6T2/jRY7e8o 2+uq4Lcd1pUBM4dk79IOt114IlDB/XLvFBA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdekgeeilecutefuodetggdotefrod 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 5E970182007A; Wed, 29 Apr 2026 10:31:18 -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: Wed, 29 Apr 2026 16:30:57 +0200 To: internals@lists.php.net Message-ID: <8ab92f4f-0fce-4239-9732-2d5c7ae1159d@app.fastmail.com> In-Reply-To: <3b2b863d-d179-40c9-ad26-8605e854a331@app.fastmail.com> 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> Subject: Re: [PHP-DEV] [RFC] Context Managers Content-Type: multipart/alternative; boundary=c6618b36c2f027dea8c9208f639dbd647ef24ce9 From: rob@bottled.codes ("Rob Landers") --c6618b36c2f027dea8c9208f639dbd647ef24ce9 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Apr 22, 2026, at 20:28, Larry Garfield wrote: > I think a key question to answer here is: Do we care to differentiate = between CM errors and underlying errors?=20 I don't think we need to differentiate at the CM level. Suppression is a= policy decision that belongs to the caller, not the context manager. Th= e CM's job is cleanup: rollback the transaction, close the file, release= the lock, etc. Whether the exception continues propagating after that i= s the caller's call, and `try using` already provides 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 get= out. If cleanup 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 differentiate, they already have `t= ry using` for exactly that. It's worth noting that every example in the RFC (database transactions, = file locks, error handler swaps, async scopes) does cleanup and propagat= es. None of them actually need the power to suppress. If a context manag= er wants to give callers a clean exception hierarchy to catch against, i= t can wrap underlying exceptions in their own types during cleanup. That= 's just normal exception design, no special syntax required. =E2=80=94 Rob --c6618b36c2f027dea8c9208f639dbd647ef24ce9 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Wed, Apr 22, 2026, at 20:28, Larry Garfield wrote:<= br>
I think a k= ey question to answer here is: Do we care to differentiate between CM er= rors and underlying errors? 

= I don't think we need to differentiate at the CM level. Suppression is a= policy decision that belongs to the caller, not the context manager. Th= e CM's job is cleanup: rollback the transaction, close the file, release= the lock, etc. Whether the exception continues propagating after that i= s the caller's call, and = try using already provides exactly that:

=
try using ($db->transact=
ion() =3D> $conn) {=0A    $conn->execute('INSERT INTO orders ...');=
=0A} catch (ValidationException $e) {=0A    // Caller chooses to suppres=
s this here=0A}

That makes exitContext() simple: return void,= do your cleanup, and get out. If cleanup fails, it throws naturally, an= d the desugared form can chain the original exception as $previous so the root cause isn't= lost. If the caller wants to suppress or differentiate, they already ha= ve try using for e= xactly that.

It's worth noting that every examp= le in the RFC (database transactions, file locks, error handler swaps, a= sync scopes) does cleanup and propagates. None of them actually need the= power to suppress. If a context manager wants to give callers a clean e= xception hierarchy to catch against, it can wrap underlying exceptions i= n their own types during cleanup. That's just normal exception design, n= o special syntax required.

= =E2=80=94 Rob
--c6618b36c2f027dea8c9208f639dbd647ef24ce9--