Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129083 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 63B3D1A00BC for ; Wed, 5 Nov 2025 07:44:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1762328668; bh=fNg4MG439lrFMvmLCG5bpfAzvc1PfGFsV2zuQttZNUQ=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=nm0tjix8G2+zZZWak98fI211rmX8UYTWG0r0X+SDy+G4j3rF67KoYBamAMKzJUhRE bNBaj4X5rUerdM276/J/S6BrCoCRCexXNkk4kAtaVi568abFr+9wjOldfUpSdAM9UZ 0AQ6ZFqadWuHXGaKyHtziy1n3e75eLsQcTVmY+U2EanQO3OniuRfVIHcfBQ5aUMl/a EaS35YNydxkx2/beJwkE2k4av3ePqbDRSG2WoE/EPeRFw0We5nvnZSu6CXUNO8IxuL KBPNzNa93Lq4iYfaZzf1uLEbPeRY50PnOlT0hzk+w7oPOk3Ew5Th0/Cufuq0sXDPwP Z56HLDYuAvFrA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C754218006E for ; Wed, 5 Nov 2025 07:44:27 +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_FONT_LOW_CONTRAST,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-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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, 5 Nov 2025 07:44:27 +0000 (UTC) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2952d120da1so2653075ad.3 for ; Tue, 04 Nov 2025 23:44:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762328661; x=1762933461; 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=gGRQkF7pkSVmiFT5e5RmLS497Uyzx2nwPKvADRGQGMI=; b=lKLiNjAm1hcBlZJegDT4D2VQGiW58aSaNERCAsSP6tCjuxVNwLo2trfq5INYyxT7cf MtXgyfAUfgf+HHW5Ye7nFNgGgwqnw51oVnz1e34KwcnVez50yISdzOptCMH+ThdCdkp0 lOlPxeZimY0ddFFOZ9trTqDYyPUvtnqHthqVSYaKYsVE6kw/i0xJXhkUUJXEZYBRZXHC kUDW3rMm2gktIdto+L8n0NZJ6YNH8zEw05TzxHiO4vCDWFqXECq9rnidu13VXqRtJQm9 eH4qiC0cEPcYVrIYYb5b3IilX4u8n5DMO7JeCc17et16JKyt4EotZH4SN+ohKtl2gDWL eIlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762328661; x=1762933461; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gGRQkF7pkSVmiFT5e5RmLS497Uyzx2nwPKvADRGQGMI=; b=hnS0un+e0yipR2AQDVz4PkPpSWcTvZNbQpYP7XlLLkM8hGXiGu65N4p2yTXFnkASF9 TQ9VwM9U/qMthCUieVDIVfkSqRSk22gJVB06yS2nHQ6UJWD+wPGzfZs6F9M63kuvFfHc De8XAs0rn/rULczeluOGoCgc74Pmw+j0WmF7Rc8Llag9R2PLKhNxjknZCVUm0h8MOvHC DRCrcuWwyfMNBeNa7H0XteFmPhx1qzi/wUCEl5qKEkC9Fd0d3l38YzhLmg/kQ5GZHqfo /agCCWvvJpeaUc1hjLlpIEq5HEtV0dZRcMLmKMU9HAJOZqV3b41Sruoir+fUSWqj5lyR fdOQ== X-Gm-Message-State: AOJu0YxKPYJJBz8WTvA1kpb2Ck4kQm6C13aTthSS6FfYnI4b+Wf/sNZs YCjUn5fbV86OszQNXCK0IiT0vcP1WCWIUOcL6eTISe0YYM4nBAFkuFHCP5olKfNOVw8HHTZ9GHv 8LU6cQB1GXnzVp4gY1YzDWGpnd3KGe3RJXA== X-Gm-Gg: ASbGncvq9IhZhe89DeQM0RHd2OtfEQMd9EP9lNQrWySF5RRqQ7f4TtQCuZ7BRKmkU/P Vsol9/b9i19D7uOWQkhvUEwdndeZYy4lMV8KPbfpY483Yw6muiPoa9H3KgS4qVYBdQvkCPMWMep KerSuzrn2wgcJnSS/dHsJXreracpX7oFmYn1EnioWOVrXPw24SF/XQpsQKxppH0oR1cw2pgERJN 7aYnPakJZohEZEJ4OqsM4mHi8let3zgqWuXx4WEWDpTkk3H4yEKRq8iDLpfbqd8ehSRc8Vds9nT ObaCdy6nytW85O1mzA== X-Google-Smtp-Source: AGHT+IE6ulQTPZsGZ29/77OEucW0aLiZN/DsMYmcc2CLR/QDddwve77dCQBy/Q/E0ykWdP1fQmlQUTjJB9gzbGUhHDI= X-Received: by 2002:a05:690e:2042:b0:63f:b057:24ac with SMTP id 956f58d0204a3-63fd3589b55mr968195d50.8.1762328348904; Tue, 04 Nov 2025 23:39:08 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 5 Nov 2025 04:38:58 -0300 X-Gm-Features: AWmQ_bk9ZF3KIl2RHTzP0E4sdHZEWfTxkIAiBQs7SjFr-opjLJX9sDpDZOXumlY Message-ID: Subject: Re: [PHP-DEV] [RFC] Context Managers To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000036d0bc0642d40b94" From: deleugyn@gmail.com (Deleu) --00000000000036d0bc0642d40b94 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 4 Nov 2025 at 17:18 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 unreliab= le > 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 are a few open > questions as listed in the RFC that we are seeking feedback on. > > Discuss. :-) > > -- > Larry Garfield > larry@garfieldtech.com Great RFC and I really like how much more readable the code can become with this approach. Out of curiosity, what happens if GOTO is used inside a context block to jump away from it? Could the RFC clarify the relation between Context and switch/case? I thought it was really odd that something that triggers a warning on switch/case is being introduced into a brand new language construct basically creating the possibility for new code to fall into the same trap as opposed to avoiding it in the first place. Specially a construct like switch/case that has been in decline for over a decade and ever since match came out on 8.0, switch case is practically deprecated without actually being deprecated yet. What=E2=80=99s the importance/relevance of being cons= istent with it? While we=E2=80=99re at it, do we really need break; statements inside conte= xt blocks? If you want out you can: - return - throw In the case of a nested block (break 2;) where I don=E2=80=99t want to wrap= the entire thing in try/catch, it seems like a GOTO out of it would be more meaningful with text-based identifiers rather than number-based, which leads to my first question (although I was more curious than actually making an argument for it because I would rather avoid nested with as much as possible). Marco Deleu > --00000000000036d0bc0642d40b94 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, 4 Nov 2025 at 17:18 Larry Garfield <larry@garfieldtech.com> wrote:
Arnaud and I woul= d 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 T= im and Seifeddine.=C2=A0 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.=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 unreliable= if timing matters.=C2=A0 It also does not allow differentiating between a = success or failure exit condition, which for many use cases is absolutely m= andatory (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.=C2=A0 However, there are a few = open questions as listed in the RFC that we are seeking feedback on.

Discuss. :-)

--
=C2=A0 Larry Garfield
=C2=A0 larry@ga= rfieldtech.com

Great RFC and I really like how much more readable the code can become wi= th this approach.

Out of= curiosity, what happens if GOTO is used inside a context block to jump awa= y from it?

Could the RFC= clarify the relation between Context and switch/case? I thought it was rea= lly odd that something that triggers a warning on switch/case is being intr= oduced into a brand new language construct basically creating the possibili= ty for new code to fall into the same trap as opposed to avoiding it in the= first place. Specially a construct like switch/case that has been in decli= ne for over a decade and ever since match came out on 8.0, switch case is p= ractically deprecated without actually being deprecated yet. What=E2=80=99s= the importance/relevance of being consistent with it?

While we=E2=80=99re at it, do we really need= break; statements inside context blocks? If you want out you can:

- return
= - throw

In the case of a= nested block (break 2;) where I don=E2=80=99t want to wrap the entire thin= g in try/catch, it seems like a GOTO out of it would be more meaningful wit= h text-based identifiers rather than number-based, which leads to my first = question (although I was more curious than actually making an argument for = it because I would rather avoid nested with as much as possible).

Marco Deleu
<= /a>
--00000000000036d0bc0642d40b94--