I need to write code according to the parameters of an anonymous function. The following code gives the parameters correctly.
Example code 1:
class test{
}
$func = function($a, $b, test $t, $c = 'new') {
echo 'test function ran'.PHP_EOL;
};
$info = new ReflectionFunction($func);
var_dump(
$info->getName(),
$info->getNumberOfParameters(),
$info->getNumberOfRequiredParameters()
);
result var_dump
string(9) "{closure}"
int(4)
int(3)
The result is different when I change the parameter order. Do you have any information on this?
Example code 2:
class test{
}
$func = function($a, $b, $c = 'new', test $t ) {
echo 'test function ran'.PHP_EOL;
};
$info = new ReflectionFunction($func);
var_dump(
$info->getName(),
$info->getNumberOfParameters(),
$info->getNumberOfRequiredParameters()
);
result var_dump
string(9) "{closure}"
int(4)
int(4)
I am sorry, my English is not good. I hope I can tell.