Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130413 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 7447A1A00BC for ; Sun, 22 Mar 2026 18:19:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1774203601; bh=7ANO+QkNfzuAg9wcPf5BIVdE6hGN/5a3eVQeQhCxY1s=; h=Date:From:To:In-Reply-To:References:Subject:From; b=Vay/U9ffRyItSaNje8jIBUL+MB0G3srlaznureesOc2qL0no/249ddRPqKbyxYw+E jTYknFzjEHU92F4ruZQAmyxN0OUjJFkYNXp0dx8Kam/NKl0o9WSsuB5+DX9vvJQB5T X6awQrgEjhIyZuKRKLP+BPC7vTkKQ3ttTU4KW97aAGWLabSb3Y7v9Pef8ylAXqA99b XLMkfADw9g1dNFuZwvMvcinE8lbweQeEB/N0JvY4F2v9+A0Q8obSC3jP1Q7Nvs3rSn trH4FsgbwEgJTk18NsH3rvBa6zVA0C802qpLygcWJY06qav2ZqpyBb60Y4QFQ61YlY mcfnGlmYWST5Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 13E0A180062 for ; Sun, 22 Mar 2026 18:20:00 +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,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-a2-smtp.messagingengine.com (fhigh-a2-smtp.messagingengine.com [103.168.172.153]) (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 ; Sun, 22 Mar 2026 18:19:59 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 39870140018A for ; Sun, 22 Mar 2026 14:19:54 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-04.internal (MEProxy); Sun, 22 Mar 2026 14:19:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding: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=fm1; t=1774203594; x=1774289994; bh=sRnH8vpC3f995T4spVb8x 6DpOvZIE6m8GyckfXnJvLk=; b=yif8vKA8GuwKiMzJQJefQnj3GHXx55BtIKq4c EML3KjAZ0e5l/Mn4ACslo9XUK93VRQHhzsJlaiNAtjNCuXB6GEAWzlMFvG1p9DBQ IdpV7Ttsg1oKdnCiQUxoIc8Qmsv8PNGsAk+BeDTLR3cGjRq/moBpwx9mJJid84dw YQqaIe6KBKXeMIDZ7e5pH2SwylX3GgBz+lIYff0wCAu1ICEQagykSxdgwCy0dkYO pRkTPa4SLQwjMrRHLkmGWJ3/Bxl3C9wl9/r76a1z6+B9NiAOXqNM8Rvr2SWHedUc CQB2TkumNLHFUgPmqRbNsKuA3rHfz/vZ4u4VnsTlM4q4IlSmA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=fm1; t=1774203594; x=1774289994; bh=s RnH8vpC3f995T4spVb8x6DpOvZIE6m8GyckfXnJvLk=; b=uWGjcIoJo/SIoATMW dDNdzW1lz+vCm4f28X4eQQzC76UFMWOMzbr7vfdr7ELR45AgILlIG+UgBRkzfrPL icgVcXf+2h3uBA0ctanZSg+vrB95w0v6/mIre9cZAvpNQsBuRAVfO5HSymehvwe+ spKYWh1VF0HzEhPrUfDDjJZJvs/pxWs5j6Nnvac8MaW8zQQupUSJGYLeVZhE3ZMz jIGR+2RbmtnFnaqJSP8p0DzoDsk1UHt9duDnYchkP4G8wFIIjK85i8YXGWcK8DxQ nBKomi/vpuHDLHQcgjK4h59HhXdQSEZ1ledH9pI+1TrI+avsn2GCL085lHClW7O7 We3Xg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdefudeihedtucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvffkjghfufgtgfesthejredtredttdenucfhrhhomhepfdfnrghrrhih ucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqe enucggtffrrghtthgvrhhnpeeuvedvudfhffffhfelueehvdejvefgleegteegffetudef leehgeefvdehgeelteenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghl ughtvggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpd hrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 8EA1070006F; Sun, 22 Mar 2026 14:19:53 -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: Atmh9k-BTBuN Date: Sun, 22 Mar 2026 13:19:33 -0500 To: "php internals" Message-ID: In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] Context Managers Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") 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 are > a few open questions as listed in the RFC that we are seeking feedback > on. > > Discuss. :-) > > -- > Larry Garfield > larry@garfieldtech.com Hi folks, and welcome back! Arnaud and I have made a number of changes to the RFC that should make it sleaker and more consistent. The notable ones (that impact behavior) are as follows: 1. We went back and forth on the `continue` question several times, before coming to the conclusion that `continue` is a tool for looping structures only. That `switch` also uses it is just `switch` being silly because reasons, and there is no reason `using` must inherit its weirdness. Therefore, `continue` inside a `using` block now means nothing at all. `continue` will ignore it, the same way it ignores an `if` statement. 2. Several people (including us) were uncomfortable with using a boolean return from the exitContext() method. While that is what Python does, it is indeed not self-evident how it works. (Should true mean "true, I'm done" or "true, rethrow"?) We debated using an enum value, but that appeared to be too verbose. Instead, we decided that exitContext() should return ?Throwable, which is the same thing it is passed. In a success case, it is passed null. In a failure case, it is passed a throwable. So it can then return null (meaning "we're done, nothing else to do here") or a throwable, which will then get thrown. Since in most cases an error should be allowed to propagate, it means simply calling `return $exception` at the end of the method will "do the right thing" 95% of the time. Simple and easy and self-documenting. (If there's a reason to wrap and rethrow the exception, do that and return the new exception. Or to swallow the exception and not propagate it, return null.) We believe this concludes the context manager design. We're pretty happy with where it is at this point. Baring any further substantive feedback, we'll open the vote in a little over 2 weeks. --Larry Garfield