Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Julien Pauli:
PHP closures
Jul 10, 2015 @ 15:54:29

Julien Pauli has posted a look at PHP's closures and how they're actually handled internal to the language.

Back in 2009, when PHP 5.3 got released, a new feature (among many others) were introduced : anonymous functions (also called lambdas or closures). The feature was very expected, as closures have proved their utility through several other languages, particularly javascript that web developers master. [...] Let's see together how Closures have been added to PHP, as usual by turning to the truth : the PHP source code.

He starts at the beginning (a good place to start) and talks about the work that needed to be done on the internals before closures could even be introduced. He walks through the changes made to object handling to make them "callable" and the addition of the "zend_closure" object type. He then gets to the part where "the magic happens" and shows how the userland closure is translated and executed. He ends the post with a look at two other topics: scoping with "$this" and the special handling that was needed for reflection and direct calls to "__invoke".

tagged: closure language functionality object callable scope reflection invoke

Link: http://jpauli.github.io/2015/07/08/php-closures.html


Trending Topics: