【发布时间】:2013-07-15 20:16:49
【问题描述】:
我有一个带有两个参数的函数:
function index($LoadFunction, $footer) {
// My statements
}
我可以像这样index(1,2,3,4) 得到发送给这个函数的参数总数
$numargs = func_num_args();
echo "Number of arguments: $numargs\n";
我想知道我可以向这个index() 函数发送多少个参数。
我将如何做到这一点。
EDIT1:
我也试过这些,但这并没有回应任何东西
https://stackoverflow.com/a/346789/1182021
https://stackoverflow.com/a/346943/1182021
EDIT2:
好的,我会用更恰当的方式解释:
类富 { 功能栏(arg1,arg2){ ...... } }我这样称呼foo类:
现在我想做的是:
$method = new ReflectionClass('foo', 'bar'); $num = $method->getNumberOfParameters(); // 理想情况下,这应该给我这个'bar'的参数总数 // 函数可以接受,但它不会回显任何内容。所以我怎么能得到这个,我不想进入函数来检查它:I want to check it before executing the function.
我如何使用这个东西:
ReflectionFunctionAbstract::getNumberOfParameters — 获取参数数量 ReflectionFunctionAbstract::getNumberOfRequiredParameters — 获取所需参数的数量【问题讨论】:
-
@zerkms 嘿,这很好,我已经完成了,但无法完成。你能给我一些关于如何使用它的想法吗?
-
通过链接查看第一条评论
-
@bansi 不像你给的那样高。我想在运行函数之前检查函数
required arguments接受的参数总数。
标签: php function oop parameters arguments