Home  >  Article  >  Backend Development  >  PHP externally obtains the number of function parameters_PHP tutorial

PHP externally obtains the number of function parameters_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:51:51825browse

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……

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371715.htmlTechArticlefunction War($a,$b,$c) { $n = func_num_args(); echo $n; } War(1,2,3); func_num_args() This function can only get the number of parameters inside the function but not outside the function. Is there any way...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn