I have a Router
class:
$router->
get($pattern, $callback); // creates a new route
[...]
And an Application
class:
$app->
get($pattern, $callback); // calls the router `get()` method
[...]
The problem is, when I'm setting the callback, inside each function I need the $app
instance. I know I can use the use
keyword, but using it for every route, every callback will by annoying and pointless.
Example:
Change:
$app->get('here/is/my/pattern', function () use ($app) {
$app->controller('just_an_example');
});
To:
$app->get('here/is/my/pattern', function () {
$app->controller('just_an_example');
});
How can I pass a variable to an anonymous function without the use
keyword?