Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130632 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 98E581A00BC for ; Tue, 14 Apr 2026 14:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1776176903; bh=4iFooRDl+KVMtWhOsTV4MxwUDxVAaUcDGu4CaCKQSWk=; h=Date:From:To:In-Reply-To:References:Subject:From; b=XRlwHqbACY4x1MLltbQersLPi+YwSDbbesBkk/CXsPfuxj6SbxEMpN1fhF5FMnvx1 QA9JUEz39RQ9hOtqT/hHfqTYjmj2aoxEAeX1FJ8JYTalJchNXWXDFqdJ3N5B+wqdxJ WSHLYRiOrH/UsO+Qmuu2tXkifbALQFfwuRfC17vX+ywkMUSxnccpq2U/2I7Lw8nCtu McAMzvRwwdA8Z5KXnfv0BE8OtA2nZZtVEOUCSeEckuIlUvmO9uf21fX0pL0wFjLEWa jLy+7B/6ukxtGd1RmGi+xEhryE9wkN+wGLMwvVDSuwghBvFkeLpjClzUEDktXqRg/8 Sjfw9HL6WFtLQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9149B1801D4 for ; Tue, 14 Apr 2026 14:28:22 +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-b7-smtp.messagingengine.com (fout-b7-smtp.messagingengine.com [202.12.124.150]) (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 ; Tue, 14 Apr 2026 14:28:22 +0000 (UTC) Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfout.stl.internal (Postfix) with ESMTP id 36BF61D00084 for ; Tue, 14 Apr 2026 10:28:17 -0400 (EDT) Received: from phl-imap-05 ([10.202.2.95]) by phl-compute-12.internal (MEProxy); Tue, 14 Apr 2026 10:28:17 -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=1776176897; x=1776263297; bh=vLp0RE+HBz BtMkQVOY7WCMmVqm4kP5aA+3FE3m+qNOc=; b=QQ1uKWY+IC8wT4C28SvXht7xVG 10ZErt3aKlM8qPBSd8IueMtNxPNByUtKYzCod/B7anb6JHOa/NpbJ3bVuTVfaVwG iXXgVjngRDN1eDS7UrLv6a8Ehu/3qoVrwqlMKVfda9x51DzTLz8EEOr4uJQJ/nE2 fIO5fYs1mSF5n7dnVl2+OQE3YIgBtcRbyAQBRX30t+SXIoFpV6fRQfDLqsWJliQM 43UyzkyNV6GFKBHJ3UX2wgaoJZRZl1t4GUbOH6GTwhqcS2y+4atXVrEKZKzE6zwV Q0RN4OXYcC2mbTPG+YXWIypc/9pz0aQaSOdWfJ76YS9aQNdHGE48DP/aAsig== 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= 1776176897; x=1776263297; bh=vLp0RE+HBzBtMkQVOY7WCMmVqm4kP5aA+3F E3m+qNOc=; b=l2Q2YS846B1aMG6dmvCtBiekEe5Emn5oDfEEsk1GZ2Tbi3yT8iv 1Ss8QW0W3giTlQFO/GAQckUYF6m2uKsRKsBWt2gR+sCpTx8ryG1evyNMnvn9pbm0 s+o5FDJqyNdX9MeggVTqYLuEwDTlJQSdB2kBWmOqt44FUFsAS82IbV54mne3swFA kGedT154U0cZu9rwzh1WRpFQGMAWJccU6+roKvrVTU6iD4ecrtKkh4xAvgG+GKzf Cdec1BjcorxaHCoQ2MehH7iHgTt8QfCk/pcohRP1YHDukT0IbiKTWsYapHso1Mue SEH++KDdMN5WMkOsf2B1Y/qdxdJd/Pikuxg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdegudeflecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecunecujfgurhepofggfffhvffkjghfufgtsegrtderreertd ejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdr tghouggvsheqnecuggftrfgrthhtvghrnhepleekhedtgfefhfelieelgfegiefhkedvle efjedtffelhfehheffgfduteduuddtnecuffhomhgrihhnpehphhhprdhnvghtnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhosgessghoth htlhgvugdrtghouggvshdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhht pdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id D667F1820082; Tue, 14 Apr 2026 10:28:16 -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: Tue, 14 Apr 2026 16:27:50 +0200 To: internals@lists.php.net Message-ID: In-Reply-To: <4985896b-c80a-4302-912e-9f572a260fb5@app.fastmail.com> References: <4985896b-c80a-4302-912e-9f572a260fb5@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Context Managers Content-Type: multipart/alternative; boundary=369161d25520f133fb0ff4371829dc63c0801f62 From: rob@bottled.codes ("Rob Landers") --369161d25520f133fb0ff4371829dc63c0801f62 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Apr 14, 2026, at 16:18, Rob Landers wrote: >=20 >=20 > On Tue, Nov 4, 2025, at 21:13, Larry Garfield wrote: >> Arnaud and I would like to present another RFC for consideration: Con= text Managers. >>=20 >> https://wiki.php.net/rfc/context-managers >>=20 >> You'll probably note that is very similar to the recent proposal from= Tim and Seifeddine. Both proposals grew out of casual discussion sever= al months ago; I don't believe either team was aware that the other was = also actively working on such a proposal, so we now have two. C'est la = vie. :-) >>=20 >> Naturally, Arnaud and I feel that our approach is the better one. In= particular, as Arnaud noted in an earlier reply, __destruct() is unreli= able if timing matters. It also does not allow differentiating between = a success or failure exit condition, which for many use cases is absolut= ely mandatory (as shown in the examples in the context manager RFC). >>=20 >> The Context Manager proposal is a near direct port of Python's approa= ch, which is generally very well thought-out. However, there are a few = open questions as listed in the RFC that we are seeking feedback on. >>=20 >> Discuss. :-) >>=20 >> --=20 >> Larry Garfield >> larry@garfieldtech.com >>=20 >=20 > Hi Larry/Arnaud, >=20 > This is a pretty exciting thread and fascinating proposal. That being = said, I have a couple of subtle questions that don't seem to be answered= in the (very long) thread or the RFC itself -- If I missed it, please l= et me know: > 1. What happens if a Fiber is suspended in the using block and never= resumed? When is the using block released to clean up the context? > 2. There's still no mention of how this should affect debugging, will= we see the "desugared" or "sugared" version? Is that even a concern for= the RFC? > 3. I will say it is weird to have exitContext return an exception; bu= t what happens if an exception is thrown during exitContext? Why not jus= t have it return void and throw if you need to throw instead of having t= wo paths to the same thing? > 4. Looking at the desugared form ... I'm a bit confused: if exitConte= xt is called during the finally path and returns an exception, it is jus= t swallowed? But if it is thrown, it won't be? > 5. That being said, I don't think the RFC shares with us when we shou= ld return an exception vs. throw an exception. >=20 > =E2=80=94 Rob Maybe the desugared version should look more like this? } catch (\Throwable $e) { try { $__mgr->exitContext($e); } catch (\Throwable $cleanupException) { throw new ContextManagerException( $cleanupException->getMessage(), previous: $e ); } throw $e; } =E2=80=94 Rob --369161d25520f133fb0ff4371829dc63c0801f62 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Tue, Apr 14, 2026, at 16:18, Rob Landers wrote:

On Tue, Nov 4, 2025, at 21:13, Larry Garfield wrote:
Arnaud and I would = like to present another RFC for consideration: Context Managers.


Y= ou'll probably note that is very similar to the recent proposal from Tim= and Seifeddine.  Both proposals grew out of casual discussion seve= ral months ago; I don't believe either team was aware that the other was= also actively working on such a proposal, so we now have two.  C'e= st la vie. :-)

Naturally, Arnaud and I feel tha= t our approach is the better one.  In particular, as Arnaud noted i= n an earlier reply, __destruct() is unreliable if timing matters.  = It also does not allow differentiating between a success or failure exit= condition, which for many use cases is absolutely mandatory (as shown i= n the examples in the context manager RFC).

The= Context Manager proposal is a near direct port of Python's approach, wh= ich is generally very well thought-out.  However, there are a few o= pen questions as listed in the RFC that we are seeking feedback on.

Discuss. :-)

-- 
  Larry Garfield


Hi Larry/Arnaud,

This is a pretty exciti= ng thread and fascinating proposal. That being said, I have a couple of = subtle questions that don't seem to be answered in the (very long) threa= d or the RFC itself -- If I missed it, please let me know:
<= ol>
  •  What happens if a Fiber is suspended in the using block and= never resumed? When is the using block released to clean up the context= ?
  • There's still no mention of how this should affect debugging, = will we see the "desugared" or "sugared" version? Is that even a concern= for the RFC?
  • I will say it is weird to have exitContext return = an exception; but what happens if an exception is thrown during exitCont= ext? Why not just have it return void and throw if you need to throw ins= tead of having two paths to the same thing?
  • Looking at the desug= ared form ... I'm a bit confused: if exitContext is called during the fi= nally path and returns an exception, it is just swallowed? But if it is = thrown, it won't be?
  • That being said, I don't think the RFC shar= es with us when we should return an exception vs. throw an exception.

    =E2=80=94 Rob

    Maybe the desugared version should look mo= re like this?

    } catch (\Throwable $e) {=0A    try {=0A        $__mgr->exitCo=
    ntext($e);=0A    } catch (\Throwable $cleanupException) {=0A        thro=
    w new ContextManagerException(=0A            $cleanupException->getMe=
    ssage(),=0A            previous: $e=0A        );=0A    }=0A    throw $e;=
    =0A}

    =E2=80=94 Rob
    --369161d25520f133fb0ff4371829dc63c0801f62--