> Am 31.01.2017 um 21:45 schrieb Andrea Faulds <a...@ajf.me>: > > Hi Marc, > > Marc Bennewitz wrote: >> - Also I like the "use" keyword you have to define your variables >> >> -> Would it be helpful to allow "function () use (*) {}" to inline >> all available variables? > > I did think of that, but it's not as concise as not having to specify `use` > at all. You could take the opposite approach and auto-capture by default, but > permit `use ()` to capture nothing, alongside regular `use (...)` for > explicit capture of variables. > > Thanks. > > -- > Andrea Faulds > https://ajf.me/
Hey Andrea, you realize that you are actually proposing quite a heavy BC break? Any code which uses the same variable than in parent scope and does not overwrite it before its first usage will break. E.g.: $foo = [1,2,3]; // more code working on foo doSomeAction(function($bar) { // waaah, $foo is now [1,2,3] instead of null foreach ($bar as $x) { $foo[] = $x; } return $foo; }); Or what I have seen in real code: $response_text = "Do action"; store_response($response_text); // much later doSomeAction(function() { $response_text .= "Do other action"; // Note that accidental .= instead of = store_response($response_text); }); The code still works as expected, because things are NULL-initialized currently. Now with implicit auto-capture this is breaking. No ahead of time errors like parse or compile errors, which warn you. Just subtly breaking. Depending on where it's done, it may not be even noticed soon (variables with the same name at different places tend to have compatible types), just misbehave subtly. This is not acceptable. Now, when you suggest "function($bar) use (*) => $foo + $bar", I feel like half the point of the RFC, the conciseness of the syntax, is missed. And I'd also reject function($bar) => $foo + $bar as this would mean the "function" keyword introducing different semantics depending on what follows. [apart from being still not as concise as "fn"] Thanks, Bob -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php