TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Functional PHP 5.3 - What are Anonymous Functions and Closures?

25 点作者 KrisJordan将近 16 年前

5 条评论

yannis将近 16 年前
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 未加载
phicou将近 16 年前
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.
HeyLaughingBoy将近 16 年前
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 未加载
gdp将近 16 年前
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 未加载
pbhjpbhj将近 16 年前
"intents and purposes"
评论 #770764 未加载