I've seen the function () use ($app) {
syntax done over and over again in the Lumen docs here.
The full syntax looks like that:
$app->group(['middleware' => 'auth'], function () use ($app) {
$app->get('/', function () {
// Uses Auth Middleware
});
});
Is this thing somehow related to the PHP? Lumen? Is it also available in the Laravel?
It looks like the anonymous function in PHP without the curly brackets, however, the use
keyword doesn't make sense in the context of this particular code example. As far as I know, using use
could be like an alias or the trait in the context of OOP.
Tried changing it a little bit, because I'm not a huge fan of the function ()
:D My attempt using function () { use ($app) {
results in the syntax error.
I haven't seen anything like that in the PHP before, could you give me some details about it?