Home > php教程 > php手册 > PHP 外部获取函数参数个数

PHP 外部获取函数参数个数

WBOY
Release: 2016-06-13 11:34:24
Original
1070 people have browsed it

function War($a,$b,$c)

{

$n = func_num_args();

echo $n;

}

War(1,2,3);

func_num_args()这个函数只能在函数里面获取参数个数而不能在函数外部获取,有什么方法能在外部获取函数参数的个数呢?

--------------------------------------------------------------------------------
func_num_args()得到的是传递给宿主函数的参数个数

--------------------------------------------------------------------------------
func_num_args()得到的是实际传递的参数个数,而不是预定义个数,所以不应该有“外部获得”的说法
PHP code

function War()

{

$n = func_num_args();

echo $n;

}

War(1,2,3);

War(1,2,3,4);

War(1,2);
--------------------------------------------------------------------------------
实在要在“外部获取”倒是可以利用自定义函数的注释,用反射来获取

PHP code
/**
* 某自定义函数
*
* @param string $a
* @param string $b
* @param string $c
*/
function War($a,$b,$c){}

/**
* 某自定义函数2
*
* @param s……

 

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template