Re: Examples comparing Bl ock Scoped RAII and Context Managers

From: Date: Wed, 17 Dec 2025 23:04:21 +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-129646@lists.php.net to get a copy of this message
On 17 December 2025 19:59:54 GMT, "Tim Düsterhus" <tim@bastelstu.be> wrote: > let ( > $scoped = new Scoped(), > $scoped, > ) { My attempts to guess what this would do went something like this: 1) The second mention of $scoped does nothing, you've already declared it as scoped to this block 2) That seems trivial for the compiler to spot, so probably an Error 3) Maybe it overwrites the variable to null? But that would make the lifetime shorter, not longer 4) So, somehow, there are two variables, with the same name, and they both live until the end of the block? 5) Wait, does that mean this is just a sequence of declaration statements in disguise? It feels like this completely goes against everything you've been saying about avoiding the ambiguity of ALGOL-style declarations. If you can do that, presumably you can do this: let( $foo = bar($baz), // What is $baz referring to? Particularly if it is a by-reference out parameter. $baz = 1, ) Which is a direct translation of an example you gave here: <https://externals.io/message/129059#129583> Thinking about it, even the dynamic coding features of PHP you say would be so difficult aren't automatically prohibited: let( $foo = compact('bar'), $bar = extract($foo), ) and so on. I kind of hope I'm misunderstanding something here, because this feels like a pretty big hole in the premise. Rowan Tommins [IMSoP]

« previous php.internals (#129646) next »