> On Jun 11, 2022, at 10:01 PM, Larry Garfield <la...@garfieldtech.com> wrote: > > On Sat, Jun 11, 2022, at 4:14 PM, Rowan Tommins wrote: >> On 09/06/2022 17:34, Larry Garfield wrote: >>> Last year, Nuno Maduro and I put together an RFC for combining the >>> multi-line capabilities of long-closures with the auto-capture compactness >>> of short-closures ... Arnaud Le Blanc has now picked up the flag with an >>> improved implementation ... The RFC has therefore been overhauled >>> accordingly and is now ready for consideration. >>> >>> https://wiki.php.net/rfc/auto-capture-closure >> >> >> First of all, thanks to all three of you for the work on this. Although >> I'm not quite convinced yet, I know a lot of people have expressed >> desire for this feature over the years. > >> To go back to the point about variable scope: right now, if you're in a >> function, all variables are scoped to that function. With a tiny handful >> of exceptions (e.g. superglobals), access to variables from any other >> scope is always explicit - via parameters, "global", "use", "$this", and >> so on. If we think that should change, we should make that decision >> explicitly, not treat it as a side-effect of syntax. >> >> I don't find the comparison to a foreach loop very convincing. Loops are >> still only accessing variables while the function is running, not saving >> them to be used at some indeterminate later time. And users don't "learn >> to recognize" that a loop doesn't hide all variables from the parent >> scope; it would be very peculiar if it did. > > There are languages that do, however. Some languages have block-scoped > variables by default (such as Rust), or partially blocked scoped depending on > details. PHP is not one of them, but to someone coming from a language that > does, PHP's way of doing things is just as weird and requires learning.
Working in Go now for several years I'd say one of its biggest foot guns that I consistently run into when doing code reviews and even in my own code is block-level scoping where one variable shadows the same named variable outside the block and the inner variable is updated when the intention was to update the outer variable. In short, block level scoping is a convenience that does more harm than good. At least in my experience. Thus I would highly recommend *not* adding block level variable scope to PHP where a block in the middle of a function shadows a variable outside the block, and that variable is used below the block, such as for a return value. #jmtcw #fwiw -Mike -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php