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 > [email protected]
I didn't mention this explicitly, so I'll do that now: * We have changed the keyword from `with` to `using`, to avoid conflicting with existing global functions in Laravel. * As requested, we've added support for multiple context managers in a single block. They simply transpile to nested try-catch-finally blocks. There's still 2 outstanding questions: * Is there any interest in turning `using` into an expression rather than a statement, so that it can be used in expression contexts? * Does anyone want to argue about how `continue` should behave? Right now it matches `switch`, for better or worse. We're happy going with whatever the consensus is. If there's no feedback or consensus, we'll go with the current implementation. To me, Rowan's experimentation really shows the value of splitting the manager variable from the context variable. The amount of flexibility gained is dramatic, and it makes many implementations much easier. --Larry Garfield
