TL; DR The short answer is no. You need to specify variables
You do not need closure variables for this. You cannot even use use with named functions, since it will not have a nested lexical scope. Use the global to make variables dynamic. You must specify all special variables.
$foo = 12; $bar = 'hello'; function run() { global $foo,$bar; $foo = 13; $bar = 'bye'; } run(); print "$foo, $bar\n";
For lexical anonymous functions, you need to name all the variables with use and use & to get the link:
$foo = 12; $bar = 'hello'; $run = function () use (&$foo,&$bar) { $foo = 13; $bar = 'bye'; }; call_user_func($run); print "$foo, $bar\n";
Sylwester
source share