Re: [RFC] Alternative "use" syntax for Closures
| From: | Wes | Date: | Sun, 16 Jun 2019 12:25:37 +0000 |
| Subject: | Re: [RFC] Alternative "use" syntax for Closures | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-105951@lists.php.net to get a copy of this message | ||
Hi Alexandru,
I don't think there is intention to do that. In particular with pass by
reference. Importing variables by-ref likely will be explicit, given recent
discussions on the matter.
The new Closures or the old ones might automatically "copy" all variables
(by-value) at some point, but I doubt they will ever "inherit" variables
automatically (by-reference).
Hence the proposed syntax or some other one will be needed for that. e.g.:
```
$foo = 123;
$fn1 = fn() => {
echo $foo; // auto import by value
};
$fn2 = fn() => {
use &$foo; // import by ref
echo $foo;
};
$foo = 456;
$fn1(); // 123
$fn2(); // 456
```