Re: Examples comparing Bl ock Scoped RAII and Context Managers
| From: | Rowan Tommins [IMSoP] | Date: | Thu, 27 Nov 2025 14:43:45 +0000 |
| Subject: | Re: Examples comparing Bl ock Scoped RAII and Context Managers | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-129466@lists.php.net to get a copy of this message | ||
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]