Good tutorial. A more practical application would have enhanced the article. Closures in PHP, just forget them!<p>As a byline, it is posted at recessframework. I did not know about the framework. Downloaded it gave it a spin and was impressed!
This should be a big help in writing clean server-side sorts by an arbitrary column in tabular data.<p>Previously we've had to do some rather ugly things with "create_function" and lots of escaping in order to make arbitrary sort comparator functions.<p>An example of the old style:<p><pre><code> private function makeCompare($field, $desc) {
return create_function('$a,$b', "
\$r = strcasecmp(\$a['$field'], \$b['$field']);
return " . ($desc ? '-1' : '1') . " * \$r;");
}
</code></pre>
Not my proudest moment, to be sure.
Nice article, but it still doesn't answer the question I've always had about anonymous functions: why are they more "important" (read: why is everyone making such a big deal about them) than pointers-to-functions in C? I've written C/C++ code that pass functions as arguments to other functions by using pointers. I could just as easily write code that returns a pointer to a function. The only difference I see here is that anonymous functions are, well, anonymous.<p>So someone clarify for me why this is any better. What am I missing?