TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Functional PHP 5.3 - What are Anonymous Functions and Closures?

25 pointsby KrisJordanalmost 16 years ago

5 comments

yannisalmost 16 years ago
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!
评论 #770623 未加载
phicoualmost 16 years ago
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.
HeyLaughingBoyalmost 16 years ago
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?
评论 #770852 未加载
评论 #770724 未加载
评论 #770725 未加载
评论 #770736 未加载
评论 #770727 未加载
gdpalmost 16 years ago
Anonymous first-class functions in PHP? I can't say that was high on my list of things I would classify as necessary to make it usable.
评论 #770720 未加载
评论 #770755 未加载
pbhjpbhjalmost 16 years ago
"intents and purposes"
评论 #770764 未加载