Re: Examples comparing Block Scoped RAII and Context Managers

From: Date: Tue, 02 Dec 2025 19:57:00 +0000
Subject: Re: Examples comparing Block Scoped RAII and Context Managers
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-129512@lists.php.net to get a copy of this message
On Thu, Nov 27, 2025, at 8:43 AM, Rowan Tommins [IMSoP] wrote: > On 27 November 2025 09:08:14 GMT, "Tim Düsterhus" <tim@bastelstu.be> wrote: >>For me the relevant keyword that indicates that the value is not used directly is not the >>'as', but the 'each' part of the 'foreach'. Just by reading it as a >>English sentence, it becomes clear to me what is happening. >> >>The same is not true for me for using (file_for_write('file.txt') >>as $fh) or even worse using (new Manager() as >>$notActuallyTheManager) (which is part of the RFC). > > > Hi Tim, > > Thanks for your thoughts. I will definitely go over your other email in > detail when I have some more time and energy, and update some of my > examples. > > Regarding this point, I think it's a really interesting observation, > and I wonder if we should be looking for different keywords that read > more clearly. For instance: > > using(new SomeManager() for $someResource) > > using($someResource from new SomeManager()) > > context(new SomeManager() giving $someResource) > > Regards, > > Rowan Tommins > [IMSoP] We're very open to tweaking the keywords. I can see the argument for "as" being a little misleading in PHP's case. Though I'd prefer to have the EXPR first and VAR second, whatever the keyword is. Another potential we thought of: Just plain =>. It already doesn't imply equals, would have no keyword breaks, and is still only 2 characters. using (new SomeManager() => $someResource) { // ... } Thoughts? --Larry Garfield

« previous php.internals (#129512) next »