13
Let’s say I have a class, and in that class i have a method, and in a parameter that method it is possible to use a anonymous function thus:
Class and method:
class Classe {
private $exemplo = [];
public function add($parametro1, $parametro2){
$this->exemplo['parametro1'] = $parametro1;
$this->exemplo['parametro2'] = $parametro2;
}
}
Use:
$classe = new Classe;
$classe->add('parâmetro 1 aqui', function(){
return 'retorno da função anonima para o parâmetro 2';
});
If I give a print_r()
in the array $exemplo
of my class, the result will be as follows:
Array ( [parametro1] => parâmetro 1 aqui [parametro1] => Closure Object ( ) )
What exactly is a Closure Object
and how can I take what was returned in this anonymous function?
Very good congratulations
– user198451