Re: [RFC] Context Managers

From: Date: Wed, 21 Jan 2026 19:06:41 +0000
Subject: Re: [RFC] Context Managers
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-129821@lists.php.net to get a copy of this message
On Wed, Jan 21, 2026, at 1:01 PM, Claude Pache wrote: >> Le 13 janv. 2026 à 23:19, Larry Garfield <larry@garfieldtech.com> a écrit : >> >> 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. :-) >> >> Hi folks. The holidays are over, so we're back on Context Managers. >> >> [...] >> >> >> --Larry Garfield > > > Hi, > > Just a small question. What happens when an > exit/die instruction is > executed inside a using block? Is the relevant > exitContext() > handler invoked, just like for an early return or > break? > > This is probably self-evident, but it is worth to state it explicitly, > because, for some hysterical reason, relevant finally blocks > are > *not* executed with exit. > > > —Claude At runtime, it's "just" a finally block, so it would behave the same. Which I agree is absurd, but this is PHP after all... --Larry Garfield

« previous php.internals (#129821) next »