Home > Article > Backend Development > PHP externally obtains the number of function parameters_PHP tutorial
function War($a,$b,$c)
{
$n = func_num_args();
echo $n;
}
War(1,2,3);
The func_num_args() function can only get the number of parameters inside the function but not outside the function. Is there any way to get the number of function parameters outside?
-------------------------------------------------- ----------------------------------
func_num_args() gets the number of parameters passed to the host function
-------------------------------------------------- ----------------------------------
func_num_args() gets the actual number of parameters passed, not the predefined number, so there should be no such thing as "external acquisition"
PHP code
function War()
{
$n = func_num_args();
echo $n;
}
War(1,2,3);
War(1,2,3,4);
War(1,2);
-------------------------------------------------- ----------------------------------
If you really want to "get it externally", you can use the annotation of the custom function and use reflection to get it
PHP code
/**
* A custom function
*
* @param string $a
* @param string $b
* @param string $c
*/
function War($a,$b,$c){}
/**
* A certain custom function 2
*
* @param s……