Am 29.04.2021 um 10:14 schrieb Rowan Tommins <rowan.coll...@gmail.com>: > On 28/04/2021 23:00, Nuno Maduro wrote: > 3) All variables are captured, there is no local scope. This is effectively > what PHP's single-expression closures use. > > Option 3 is the easy option, and is currently "good enough" because it's rare > to need a purely local variable within a single expression. For a full > function body, local variables are much more likely, so we now need to think > about the question more carefully. > > Without a keyword like "var" to declare it, I think most users would assume > that an initialisation like "$foo=null;" at the top of their closure would > make a variable local.
This assumption by the users would be true as we are capturing by value, not by reference. At the same time it feels like abusing a side-effect. But adding some sort of explicit local variable declaration seems even worse (as in even less PHP-like) to me. This illustrates why I'm wary of / opposed to auto-capture for multi-line closures. - Chris -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php