Julien Pauli has posted a look at PHP’s closures and how they’re actually handled internal to the language.
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“.