Notice that now the inner function is returned as the result of MyFunction. You can call MyFunction and store the reference to the inner function in a variable. You can then call the inner function even though the outer function is complete and none of its local variables exist any more. The inner function still has access to the variables that you listed in the use construct.
There are two points to consider here.
The first is that closures aren't as useful in a server side language as they are in a client side language. The reason is simply that closures are useful in callbacks and event handling and server side PHP uses far fewer of both.
The second problem is that $this still isn't treated properly by the inner function. That is you still have to use the $that trick and you still can't access private and protected members.
However anonymous functions do allow you to do a lot of things that would be difficult without them and they are worth knowing about.
You may not find that inner functions or anonymous functions are something that you want to use but you may have them forced upon you. All you have to do is use a framework when you can write modules of some sort that are imported into other functions or classes and you can discover that any functions you do write are inner functions just as the result of how the framework uses them.
Peachpie is a new open source PHP language to .NET compiler, which aims at full PHP 7 compatibility. Looking at it gave us the opportunity to revisit the state of dynamic language interoperabili [ ... ]
PHP is a language that creates web pages, but exactly how does it do this? If you know some HTML, you might be wondering what PHP have to do with it and how it integrates into a web page. In this arti [ ... ]