On 12.04.2012 18:21, Nikita Popov wrote:
> It would be nice to see a few real-life scenarios where this is
> useful. Right now I can't think of situations where you'd want to
> change the variable name between the outer scope and the closure
> scope. Wouldn't that just be confusion for the programmer if the same
> variable would go under two different names?
To me it's not about renaming variables, but rather avoiding to clutter
the parent scope with variables, e.g.:
$closure = function () use ($this->getFooBar() as $foo) {
$foo->stuff();
}
versus the current:
$foo = $this->getFooBar();
$closure = function () use ($foo) {
$foo->stuff();
}
They are almost equivalent, but the first with aliasing would not
declare $foo in the outer scope. A bit cleaner IMO.
Cheers
--
Jordi Boggiano
@seldaek - http://nelm.io/jordi
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php