Re: PATCH: anonymous functions in PHP
| From: | Christian Schneider | Date: | Mon, 19 Mar 2007 09:20:31 +0000 |
| Subject: | Re: PATCH: anonymous functions in PHP | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-28417@lists.php.net to get a copy of this message | ||
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