Stanislav Malyshev wrote:
Well, making it work makes this thing closure. Otherwise it's just a nice way to save a couple of keystrokes :) Not to diminish your work, but there's a danger people would think it is closure because it looks like one (i.e., in other languages closures look exactly this way, e.g. Javascript).
Wez' proposal sounds very intriguing. At the same time I wouldn't try to add closures to PHP as while they might be a mighty concept they are also complicated and have a high WTF factor IMHO. When I first started doing more complex things in Javascript I was bitten more than once by closures: Sometimes they did what I expected and sometimes they didn't (e.g. when using 'this').
But I agree that it would be great to being able to pass context to the generated function, preferably not via a global variable.
One possible solution would be to generate the function as a method of the current object and expose this so something like
usort($data, function($a, $b) { return $this->cmp($a, $b); }); could be used. - Chris -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php