Re: [RFC] Context Managers

From: Date: Tue, 11 Nov 2025 11:31:15 +0000
Subject: Re: [RFC] Context Managers
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-129195@lists.php.net to get a copy of this message
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. > 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. > 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

« previous php.internals (#129195) next »