Re: [RFC] Context Managers
| From: | Larry Garfield | Date: | Wed, 15 Apr 2026 15:10:40 +0000 |
| Subject: | Re: [RFC] Context Managers | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130640@lists.php.net to get a copy of this message | ||
On Tue, Apr 14, 2026, at 3:42 PM, Alex Rock wrote:
> Le 29/03/2026 à 13:14, Tim Düsterhus a écrit :
>> // ...
>
>
> I'm sorry that I'm arriving super late in the process, but I've
> subscribed to the mailing list only recently.
>
> To give here my 2cents:
>
> I think this RFC addresses something good (scoped code in the middle of
> a bigger chunk of code), but does it maybe a bit too bloated-ly.
Hi Alex.
I think you're missing the point of this construct. What you're describing is much closer
to the recently-declined
let scoping keyword
(https://wiki.php.net/rfc/optin_block_scoping).
The entire point of context managers is to abstract away and make reusable the try-catch-finally
logic. That logic needs to live somewhere so that it can be reused. That is what the
ContextManager object is for. It's not a complication; it's the entire purpose of the
RFC.
Since you just recently joined the list you would have missed the earlier discussion in this thread
of closures. (See https://externals.io/message/129077). In short,
closures are what people use today for this use case, but they're a PITA because they
don't support auto-capture (unless you're using the single-line version). That makes them
less common, because they're a pain to use in this case. In addition, they do create a new
scope, which... is not what we want in this case. Not creating a new scope is a feature, not a bug.
Also, this email serves as notice that I've updated the RFC again to make continue an alias of
break, as it was originally.
--Larry Garfield