Re: [RFC] Allow "use( $longname as $alias)" syntax for closures declaration

From: Date: Fri, 13 Apr 2012 01:41:51 +0000
Subject: Re: [RFC] Allow "use( $longname as $alias)" syntax for closures declaration
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-59840@lists.php.net to get a copy of this message
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

« previous php.internals (#59840) next »