Re: [RFC] Context Managers
| From: | Larry Garfield | Date: | Wed, 12 Nov 2025 15:46:23 +0000 |
| Subject: | Re: [RFC] Context Managers | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-129206@lists.php.net to get a copy of this message | ||
On Tue, Nov 11, 2025, at 5:31 AM, Derick Rethans wrote:
> On Wed, 5 Nov 2025, Larry Garfield wrote:
>
>> On Wed, Nov 5, 2025, at 1:38 AM, Deleu wrote:
>>
>> > Out of curiosity, what happens if GOTO is used inside a context
>> > block to jump away from it?
>>
>> That would be a success case, just like break or return. Basically
>> anything other than an exception is a success case. (That said,
>> please don't use Goto. :-) )
>
> I do think you might need special attention to this case, as jumping out
> of loops (such as foreach) needs to be handled with care.
I defer to Arnaud here.
>> And now the big one... also in off-list discussion, Seifeddine noted
>> that Laravel already defines a global function named
with:
>>
>> https://github.com/laravel/framework/blob/12.x/src/Illuminate/Support/helpers.php#L510
>>
>> And since this RFC would require with to be a semi-reserved
>> keyword
>> at the parser/token level, that creates a conflict. (This would be
>> true even if it was namespaced, although Laravel is definitely Doing
>> It Wrong(tm) by using an unnamespaced function.) Rendering all
>> Laravel deployments incompatible with PHP 8.6 until it makes a
>> breaking API change would be... not good for the ecosystem.
>
> PHP owns the top level namespace. That's been the going for as long as I
> can remember. It was unwise for Laravel to flaunt that rule.
Yes, Laravel is in the wrong here, but AIUI even a namespaced function would conflict with a
soft-reserved keyword. And regardless, breaking Laravel is not a great plan.
>> 1. Java uses a parenthetical block on try for similar
>> functionality
>> (though without a separate context manager). That would look like:
>>
>> try (new Foo() as $foo) {
>> // ...
>> }
>> // catch and finally become optional if there is a context.
>
> …
>
>> 2. Either use or using.
>> The semantics here would be identical to
>> the current with proposal.
>
> IMO, the try syntax is more confusing than another overload of use.
>
> cheers,
> Derick
How about using?
--Larry Garfield