I'm doing tests with a RESTFul API that I'm creating using the Slim micro-framework, and in one of those routines that is responsible for executing a particular action, I was struck by a command I did not know, which is the command use
.
Below is an example of the command use
in a method that returns a JSON with the data obtained from the database:
//Listando todas pessoas
$app->get('/pessoas/',
function() use ($app)
{
(new \controllers\Pessoa($app))->listar();
});
This command seems to be part of the anonymous function function()
that is responsible for the route:
http://localhost/RestApiEx/pessoas/
And the use of it left me with the following doubts.
Questions
I would like to know what is the purpose of the use
command and what is the relation it has with anonymous functions?