I didn't make it do anything fancy with scoping; it would make the
implementation more complicated, and wouldn't fit so well with the
way that scoping works in PHP, in that you need to explicitly
reference the global scope to "break out" of your function scope.
It would be cool if the lexical scope was inherited, but maybe not
cool enough to warrant making it work :)
--Wez.
On Mar 18, 2007, at 10:06 PM, Stanislav Malyshev wrote:
$data = array("zoo", "orange", "car", "lemon", "apple");
usort($data, function($a, $b) { return strcmp($a, $b); });
var_dump($data); # data is sorted alphabetically
What happens if you do this:
$data = array("zoo", "orange", "car", "lemon", "apple");
$rev = 1;
usort($data, function($a, $b) { return $rev?strcmp($a, $b):!strcmp
($a, $b); });
var_dump($data); # data is sorted alphabetically
This works in Javascript (probably Ruby too), but quite hard to
make work in PHP because $rev is in different scope.
Moreover, would it mean that this:
$f = function($a, $b) { return $rev?strcmp($a, $b):!strcmp($a, $b); }
would work too? Keeping right value of $rev?
--
Stanislav Malyshev, Zend Products Engineer
[EMAIL PROTECTED] http://www.zend.com/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php