mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-07 06:26:45 +02:00
Closures and variable scope
This commit is contained in:
@@ -53,7 +53,7 @@ print_r($output);
|
|||||||
|
|
||||||
Closure is an anonymous function that can access variables imported from the outside scope without using any global
|
Closure is an anonymous function that can access variables imported from the outside scope without using any global
|
||||||
variables. Theoretically, a closure is a function with some arguments closed (e.g. fixed) by the environment when it is
|
variables. Theoretically, a closure is a function with some arguments closed (e.g. fixed) by the environment when it is
|
||||||
defined. This is used to cross variable scope restrictions in a very clean way.
|
defined. Closures can work around variable scope restrictions in a clean way.
|
||||||
|
|
||||||
In the next example we use closures to define a function returning a single filter function for `array_filter`, out of
|
In the next example we use closures to define a function returning a single filter function for `array_filter`, out of
|
||||||
a family of filter functions.
|
a family of filter functions.
|
||||||
|
Reference in New Issue
Block a user