On Tue, 4 Nov 2025 at 17:18 Larry Garfield <[email protected]> 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] 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’s the importance/relevance of being consistent with it? While we’re 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’t 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 > <[email protected]>
