According to the most programming languages scope rules, I can access variables that are defined outside of functions inside them, but why doesn\'t this code work?
Another way to do it:
UPDATE 2020-01-13: requested by Peter Mortensen
As of PHP 5.3.0 we have anonymous functions support that can create closures. A closure can access the variable which is created outside of its scope.
In the example, the closure is able to access $data
because it was declared in the use
clause.