In this article, I'll continue this tour of concepts by talking about first-class functions, optimizations, and closures.
在本文中,我将继续讨论这些概念,讲解一级函数、优化和闭包。
The reflection API has great support for closures, as we've now seen, in the form of being able to create them from existing functions and methods dynamically.
正如我们所见,反射API能够通过现有函数和方法动态创建闭包,从而为闭包提供强大的支持。
I'll also circle back to some interesting comparisons between closures and higher-order functions in a later installment.
后续内容还会对闭包与高阶函数做一些有趣的对比。
After becoming comfortable with lambdas and closures, you may find yourself reducing code and creating more readable and reusable code by writing your own higher-order functions.
在适应了lambdas和closures以后,您可能会发现,通过编写您自己的高阶函数您已经减少了代码并创建了更多的可读与可用代码。
The concepts of closures and lambda functions are definitely not new ones; they both come from the functional programming world.
闭包函数和lambda函数绝对不是新出现的概念;它们均来自函数编程领域。
First-class methods and functions (closures)
一流的方法和函数(闭包)
The concept of lambda functions is the basis for closures and provides a much-improved way to create functions on the fly vs. the create_function function already in PHP.
lambda函数的概念是闭包的基础,并且提供了一种比PHP中已有的create_function函数改进了很多的动态创建函数的方法。
To support closures fully, a language needs to provide support for manipulating, invoking, and creating functions at run time and for functions to capture the environment in which they were created.
要完全支持闭包,这种语言必须支持在运行时操纵、调用和创建函数,还要支持函数可以捕获创建这些函数的环境。
These simple list-building instructions form the foundation of recursions, higher-order functions, and even higher-order abstractions like closures and continuations.
这些由列表构建的简单指令构成了递归、高阶函数,甚至是闭包和continuation之类高级抽象的基础。
We discussed lambda functions and the advantages that closures have over them.
我们讨论了lambda函数及闭包与这些函数相比的优点。
This is where closures step in and take the lambda functions to the next level.
因此出现了闭包并使lambda函数得到增强。
The above example is a good use case for closures: It USES one of the 18 standard PHP array functions that take a function as a parameter (such as array_walk, usort, and array_app).
以上示例是closures很好的使用例子:它采用18个标准php阵列函数之一,它将函数作为参数(比如array_walk、usort、和array_app)。
The above example is a good use case for closures: It USES one of the 18 standard PHP array functions that take a function as a parameter (such as array_walk, usort, and array_app).
以上示例是closures很好的使用例子:它采用18个标准php阵列函数之一,它将函数作为参数(比如array_walk、usort、和array_app)。
应用推荐