Chapter 2 of "Magento PHP Developer's Guide" states:
Zend Framework 2 uses 100% object-oriented code and utilizes most of the new features of PHP 5.3, namely namespaces, late static binding, lambda functions and closures.
While the post What is the difference between a 'closure' and a 'lambda'? has some answers (such as, that a lambda is just an anonymous function, and that a closure is a function which can access variables not in its parameter list), seems to be specific to the Python programming language (with some mention of the Scheme programming language). For instance, according to the post, in Python, it seems, there can be closures which are not lambdas, and lambdas which are not closures.
However, I am interested in the PHP programming language, not Python. One of the answers below seems to point out that in PHP all closures are lambdas, which conflicts with what the post relating to Python states.
It seems to me, that these concepts vary in the particulars from language to language, and I am interested in PHP, hence this post.
All of this is confusing. While I would assume that lambda functions in general are just unnamed functions, the following Wikipedia article says more about closures:
http://en.wikipedia.org/wiki/Closure_%28computer_science%29
although has no examples in PHP.
It's as simple as this: lambda is a language construct, i.e. simply syntax for anonymous functions; a closure is a technique to implement it -- or any first-class functions, for that matter, named or anonymous.
Lambda functions may be implemented as closures, but they are not closures themselves. This really depends on the context in which you use your application and the environment. When you are creating a lambda function that uses non-local variables, it must be implemented as a closure.
The primary difference between a lambda and a regular function is that the lambda function evaluates only a single expression and yields a function object. Consequently, we can name the result of the lambda function and use it in our program as we did in the previous example.
Basically a closure in PHP is a function that can be created without a specified name - an anonymous function. Here's a closure function created as the second parameter of array_walk() . By specifying the $v parameter as a reference one can modify each value in the original array through the closure function.
A closure is a lambda function in php that encapsulates variables so they can be used once their original references are out of scope.
A closure is a lambda function, but a lambda function is not a closure unless you specify the use
keyword.
This is a much better answer: https://stackoverflow.com/a/220728/1152375
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With