John Sonderson John Sonderson - 5 months ago 15
PHP Question

Difference between a lambda function and a closure (in PHP)?

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:

although has no examples in PHP.


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: