Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129609 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 117611A00BC for ; Mon, 15 Dec 2025 22:26:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1765837576; bh=dqP+Ldw4yARRmycRlkJcLtv3XhRCu9nqErsgkFtKRRg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=E1i/n8g7g4n0Xukz1wamh13gnQlT7bsnUtcKHpIopHEqVKgf2IsB/HShHSmyC2bdw 0ujDWdlOmByxQJCIuPKY63VLrD3T1hJz8xsSMZ0Dq5oX9L7tdg8D9XuuLWDEsYQj9R coj5CanmNIjni2/43krRf50NMV/cVK/qN+qNugiJDLaiy40Z4vA+VuyfyPAQLwJ9c1 hHqmXtdtv0+nYccdru2wj1pdXrnkqqsVkGn1A2QCF8gwMRiNTxZeJ9gfnEfyjxPMfG vFDa0UCnSFe1+p01m/SkL97YpIz3BUilU+lJGixgOd0+FtDxKwJhQvDNKvxUmaAk34 sYPvdL5iVFSWg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 844031801EC for ; Mon, 15 Dec 2025 22:26:15 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,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-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (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:26:12 +0000 (UTC) Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-5958187fa55so3231368e87.3 for ; Mon, 15 Dec 2025 14:26:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765837565; x=1766442365; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ReljxihYYzxGca56gM4BgiSEGZQvv2nnLIudEqAprQo=; b=R9d7ZG+ODWiQ9J4cZpXPOtSqCCqQPN4b1CcNxEtxG1Lb4IlTK7VyTUBT+mUKNkasmd shYnr/i/NUKpGOEPHblsPbiDWKb3rX/IC5e7Th55JZDhbtdZItKWFzJXu0hOy420i2Rh Y4ZOCRqQ5q8VulluSvRALuDmelSfAzqMXvKmjvq9r7Im7SqSB0v2JOdehJISJ6+AWSiN PIrO7Jy+JwurGcYAuk5p8stB3O8KAwixmKurIeLx6RQvBRMCY932NLHDKQKAGEmD5eBQ jxB34hsXqVj9wSxlqRUt0aI/3HR0nAqWSS6Ti7sXDT7lcsSthaHIqg4UhxoBzhQUag8w EvgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765837565; x=1766442365; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ReljxihYYzxGca56gM4BgiSEGZQvv2nnLIudEqAprQo=; b=c94ADGoseh5T9eIAeC3PIBI7TOzr4l5ec5zja44i67yOlzOXeKu6ftDhgDJfAaWwyz 206Ce8aZ0wcDt2JU+xudGf5pY7q9I8/Y8musv5YrSoUoGslY+9afk4TBliI/v7dBfb98 b/78vYNaE77JQEYk03a1tZsvOdcZbMx3viUXD5aDEZ7G1k+WEsNzxC90VYAeXIPuOw2M d/c4bohVZcUmnHxqpQKqZbtSNHxJpLcZIqjNKwYLQKSBylxjHc0ObPh7fBcEXFdU7ZUE /tmcTjU1KNVY4GXSrrTDFv4g6+yIEQ5hx/JnNyAAbg8TogJuNcIT4aWd9J9hPzPs2Qtu IdzA== X-Gm-Message-State: AOJu0Yya8/wfsTnKK44kfr9Yc6IT42+zGBVxrqcFfAu299PqSEiLWHHD aSQ4ZmH6JnSa5BrpfAfCYSLpnlboiNsMXM/WA/WxNmeylq5cTIReAGMfEjxrB8jRSHn3CzK/ffU BruXBdX/IN5HH4Xg5InaL36pCbWNt7WA= X-Gm-Gg: AY/fxX69DXgot/2931/MCnCbAaTEWlCuJSxvI38OcU+DCKx9K50vZsQuxXpWTo3T0UB Bzdg8dG2Ex4zB3Z09Ik1bfToEjRBfSobQdtyTlWme2d8EXdnCpBZG8MGE/tTSM70c23nWqT9b/P yHZOsQ3YKeb7fLIkBHT+bohe4DeSNzmVg/mbcqkTaPi7Bf6sDtAiEwoc3sIwB59mx/SFRCJ/qru Plw8cd/+W0znW4GThOXi69c3FF9q0rHgVIpNE0je5ryc8TVcaxGmbdtcYTQGDIc7VnKv0lpQR/z NylKoW9oW+oMc8QGmPKxPYiia6U= X-Google-Smtp-Source: AGHT+IFuf1WTxYvtNIzELQ9dYi2mTrVM50RcAybqIdI9V3mjv3o9rLW2TkI5CMCP+G075COgZnL1jLXnHFv7vwQycx8= X-Received: by 2002:a05:6512:1191:b0:592:f521:188a with SMTP id 2adb3069b0e04-598faa97aedmr4188357e87.49.1765837564968; Mon, 15 Dec 2025 14:26:04 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <51e16864-0867-4593-a51d-16b8e9fb8fe2@app.fastmail.com> In-Reply-To: Date: Mon, 15 Dec 2025 16:25:55 -0600 X-Gm-Features: AQt7F2qesXnQ2VxvelXwVoAgDe7kJHB_9IbtIcemX8iVSHALpXFJgsh7BQfzcUQ Message-ID: Subject: Re: [PHP-DEV] [RFC] Context Managers To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000ca822d06460518b6" From: mweierophinney@gmail.com ("Matthew Weier O'Phinney") --000000000000ca822d06460518b6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Dec 15, 2025, 3:19=E2=80=AFPM Larry Garfield wrote: > On Thu, Dec 4, 2025, at 10:46 AM, Larry 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: > >> Context Managers. > >> > >> https://wiki.php.net/rfc/context-managers > >> > >> You'll probably note that is very similar to the recent proposal from > >> Tim and Seifeddine. Both proposals grew out of casual discussion > >> several 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. :-) > >> > >> Naturally, Arnaud and I feel that our approach is the better one. In > >> particular, as Arnaud noted in 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 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, there ar= e > >> a few open questions as listed in the RFC that we are seeking feedback > >> on. > >> > >> Discuss. :-) > > > > More updates to Context Managers: > > > > * We have added "masking" for the context variable, using essentially > > 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 in the exact opposite of every other usage of =3D> we have. With associativ= e arrays, the left is assigned to the expression on the right; with arrow functions, the return value is the expression on the right; with match, the expression on the right is returned. This is going to be easy to get wrong. --=20 Matthew Weier O'Phinney mweierophinney@gmail.com https://mwop.net/ he/him > --000000000000ca822d06460518b6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable




On Mon, Dec 15, 2025, 3:19=E2=80=AFPM Larry Garfield <larry@garfieldtech.com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex">On Thu, Dec 4, 2025, at 10:46 AM, Larry Garfi= eld wrote:
> On Tue, Nov 4, 2025, at 2:13 PM, Larry Garfield wrote:
>> Arnaud and I would like to present another RFC for consideration: =
>> Context Managers.
>>
>> https://wiki.php.net/rfc/context-manage= rs
>>
>> You'll probably note that is very similar to the recent propos= al from
>> Tim and Seifeddine.=C2=A0 Both proposals grew out of casual discus= sion
>> several 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.
>>=C2=A0 C'est la vie. :-)
>>
>> Naturally, Arnaud and I feel that our approach is the better one.= =C2=A0 In
>> particular, as Arnaud noted in an earlier reply, __destruct() is <= br> >> unreliable if timing matters.=C2=A0 It also does not allow differe= ntiating
>> between a success or failure exit condition, which for many use ca= ses
>> is absolutely mandatory (as shown in the examples in the context <= br> >> manager RFC).
>>
>> The Context Manager proposal is a near direct port of Python's=
>> approach, which is generally very well thought-out.=C2=A0 However,= there are
>> a few open questions as listed in the RFC that we are seeking feed= back
>> on.
>>
>> Discuss. :-)
>
> More updates to Context Managers:
>
> * We have added "masking" for the context variable, using es= sentially
> the same technique as the block scope RFC.
> * We have added support for `try using`, as a shorthand for when you <= br> > 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 <= br> > likely proceed with the current approach of matching `switch` behavior= .
>
> There doesn't seem to be much interest in making `using` an expres= sion,
> which I find unfortunate, but that means we'll probably drop that.= =C2=A0
> Fortunately it is probably possible to change in the future if the nee= d
> 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.=C2=A0 So the n= ew syntax is

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

Going to be controversial here, but this is confusing, because it operates= in the exact opposite of every other usage of =3D> we have. With associ= ative arrays, the left is assigned to the expression on the right; with arr= ow functions, the return value is the expression on the right; with match, = the expression on the right is returned.=C2=A0

<= /div>
This is going to be easy to get wrong.=C2=A0


--=C2=A0
Matthew Weier O'Phinney
<= a href=3D"https://mwop.net/">https://mwop.net/
h= e/him
--000000000000ca822d06460518b6--