Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129610 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 894321A00BC for ; Mon, 15 Dec 2025 22:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765839528; bh=KhqbYX8yDCrFKH+TnYicTtDtpB0qMW+K8aELWkeKpB4=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=GWhJR+K05HA+eP3vVmYkuEhnh55JxzQ27P1js7V3yT/FytddxB+UWnaiLkSKQdLja XGST8yTweDV8KUHJag+sDdlJ2I36nPyDOhkFb1aCwd9ZTji9ebbfKRBnq2KplMe+bv 2u9lbTGqzsXJSrjmx032fl9yK+vdSGgN0FvmWjRcrezkQMGFzg7YHEbZvTEPlzWypI kCQK7EM/CPKDY8sqyglAaK0NMhWc6cnFHnfyVxHtZrvFS8dFGEV9RpP5GsIhA3iArL cN5e/DxLJoc0d3yAaKVKx+7l+5lsBQxyQ7HYdmQJyk61w/tAocjFGdSQ+gpJmSkfMk kmS0LTcBqatog== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 284791801DB for ; Mon, 15 Dec 2025 22:58:47 +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=1.5 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, MIME_HTML_ONLY,MIME_HTML_ONLY_MULTI,MIME_QP_LONG_LINE,MPART_ALT_DIFF, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-yx1-f48.google.com (mail-yx1-f48.google.com [74.125.224.48]) (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 ; Mon, 15 Dec 2025 22:58:46 +0000 (UTC) Received: by mail-yx1-f48.google.com with SMTP id 956f58d0204a3-640d4f2f13dso4338720d50.1 for ; Mon, 15 Dec 2025 14:58:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benramsey.com; s=google; t=1765839521; x=1766444321; darn=lists.php.net; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=f4RekmKyZb9TpqDaeUBIr+bjnmGi212Y7TtBrCPq5UY=; b=X1ssrCBlDnhKw+NXz13agdiqx5TmDWfg2Y1/jae9vIoD6r62n3hAuRYhwOF/MLUS6O udvVF2eHWgzPcMPbt9d/Kg4F4P24UroRSErZFapB7RMXbfgAh8hClxV1M63923vQR78v YD/vDZKqFQmvrbzWP5JAdN9CoiKn6LQ/9MpEl/beIgWB3YCy3l/mTOJ4XmCT7QRjQc09 QvgL9V76nxwAHmt5jZMF4eQaXx1nBBpwflW7H4uAuY7G4O5tfwbl6caMZFeLCKC2hzLH U8upkpM7bCYTYgvy0FpPA9BPBOGi85iU+ngeDtw//q29R/s5+yR30p5Mc/dcQQ4YluwN pG0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765839521; x=1766444321; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=f4RekmKyZb9TpqDaeUBIr+bjnmGi212Y7TtBrCPq5UY=; b=bpQonmVAUtozoOyNV8zEbY93ipSta8Mt8fAZyEE2ysVEbJFLNgSldx7hNo3B4GVPiH X7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p-Source: AGHT+IHXoB4WdqoOepX1genUhXQiTs9Bqj1yw9d4eUKLFjStOb9J2OluHHUZJ0WjGb1xF5WgeIa4Bw== X-Received: by 2002:a05:690e:14ce:b0:644:60d9:864d with SMTP id 956f58d0204a3-645556806e2mr7924727d50.92.1765839521242; Mon, 15 Dec 2025 14:58:41 -0800 (PST) Received: from smtpclient.apple (h96-61-170-179.lvrgtn.broadband.dynamic.tds.net. [96.61.170.179]) by smtp.gmail.com with ESMTPSA id 00721157ae682-78e749e550csm32738257b3.29.2025.12.15.14.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Dec 2025 14:58:40 -0800 (PST) Content-Type: multipart/alternative; boundary=Apple-Mail-645CD359-5CD0-491F-984E-9A3BAA413D99 Content-Transfer-Encoding: 7bit Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow Mime-Version: 1.0 (1.0) Subject: Re: [PHP-DEV] [RFC] Context Managers Date: Mon, 15 Dec 2025 16:58:30 -0600 Message-ID: <70A79513-5503-467E-BC6F-2B0494A3EBB9@benramsey.com> References: Cc: Larry Garfield , php internals In-Reply-To: To: Matthew Weier O'Phinney X-Mailer: iPhone Mail (23C55) From: ben@benramsey.com (Ben Ramsey) --Apple-Mail-645CD359-5CD0-491F-984E-9A3BAA413D99 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Dec 15, 2025, at 16:29,= Matthew Weier O'Phinney <mweierophinney@gmail.com> wrote:

=
On Mon, Dec 15, 2025, 3:19=E2=80=AFPM Larry Garfield <larry@garfieldtech.com> wrote:<= br>
On Thu, Dec 4, 2025, at 10:46 AM, Lar= ry Garfield wrote:
> On Tue, Nov 4, 2025, at 2:13 PM, Larry Garfield wrote:
>> Arnaud and I would like to present another RFC for consideration: <= br> >> Context Managers.
>>
>> https://wiki.php.net/rfc/context-managers=
>>
>> You'll probably note that is very similar to the recent proposal fr= om
>> Tim and Seifeddine.  Both proposals grew out of casual discuss= ion
>> several months ago; I don't believe either team was aware that the <= br> >> other was also actively working on such a proposal, so we now have t= wo.
>>  C'est la vie. :-)
>>
>> Naturally, Arnaud and I feel that our approach is the better one.&n= bsp; In
>> particular, as Arnaud noted in an earlier reply, __destruct() is >> unreliable if timing matters.  It also does not allow differen= tiating
>> between a success or failure exit condition, which for many use cas= es
>> is absolutely mandatory (as shown in the examples in the context >> manager RFC).
>>
>> The Context Manager proposal is a near direct port of Python's
= >> approach, which is generally very well thought-out.  However, t= here are
>> a few open questions as listed in the RFC that we are seeking feedb= ack
>> on.
>>
>> Discuss. :-)
>
> More updates to Context Managers:
>
> * We have added "masking" for the context variable, using essentially <= br> > the same technique as the block scope RFC.
> * We have added support for `try using`, as a shorthand for when you > want to wrap a try-catch-finally around a using statement anyway.
>
> More details of both are in the RFC.
>
> As no one seems to have a strong opinion on `continue`, we will most > likely proceed with the current approach of matching `switch` behavior.=
>
> There doesn't seem to be much interest in making `using` an expression,=
> which I find unfortunate, but that means we'll probably drop that. = ;
> Fortunately it is probably possible to change in the future if the need=
> arises (the way `throw` was changed).
>
> --Larry Garfield

Since the only feedback on what to use for "as" was that =3D> makes sense= , we have changed the RFC to use =3D> instead.  So the new syntax is=

using (new CM() =3D> $cVar) {
  // Do stuff here.
}

= Going to be controversial here, but this is confusing, because it operates i= n the exact opposite of every other usage of =3D> we have. With associati= ve arrays, the left is assigned to the expression on the right; with arrow f= unctions, the return value is the expression on the right; with match, the e= xpression on the right is returned. 

<= div dir=3D"auto">This is going to be easy to get wrong. 

I agree with Matthew.

<= /div>
I think it makes more sense to reverse them, like this:
=
 =   using ($cVar =3D= > new CM()) {
        // Do stuff here.
    }

I think it=E2=80=99s still clear wha= t this is doing, when reading it.

Cheers,
Ben

= --Apple-Mail-645CD359-5CD0-491F-984E-9A3BAA413D99--