On Apr 12, 2012, at 12:21, Nikita Popov wrote: > On Thu, Apr 12, 2012 at 6:06 PM, Laruence <larue...@php.net> wrote: >> On Fri, Apr 13, 2012 at 12:04 AM, Dmitri Snytkine >> <dsnytk...@ultralogistics.com> wrote: >>> I'm curious to know the benefits of this. >>> Care to explain why or when this would be useful? > > 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?
How about something like this: function f() { … $longButDescriptiveVariableUsedForSeveralThings = …; ... usort($arr, function($a, $b) uses($longButDescriptiveVariableUsedForSeveralThings as $sortKey){ return $b->$sortKey - $a->$sortKey; }); } Function parameters are named such that they're relevant to the function, not the caller. Closure variables should be seen as a (special case of) function parameter in that respect. -John -- John Bafford http://bafford.com/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php