如何在filter_input()上使用ReflectionFunction?

时间:2010-06-01 11:56:36

标签: php reflection

这是我到目前为止所得到的;

<?php ReflectionFunction::export(new ReflectionFunction(filter_input()));

我收到此错误: 警告:filter_input()需要至少2个参数,0在第2行的C:\ wamp \ www \ POS \ Ch4 \ inspect_filter_input_function.php中给出

如果我摆脱了括号,我会收到一个警告,但我是函数的信息。如果我把两个未定义的变量放在一边抱怨,我什么也得不到。我想知道我是否可以举例说明如何用参数反映函数。

1 个答案:

答案 0 :(得分:2)

ReflectionFunction :: export()需要一个字符串(函数名称)作为第一个参数,而不是 ReflectionFunction 对象:

ReflectionFunction::export('filter_input');
/* Output:
Function [ <internal:filter> function filter_input ] {
}
*/

$ouput = ReflectionFunction::export('filter_input', true);

另一种方法是直接打印ReflectionFunction对象,因为它实现了魔术方法__toString():

echo new ReflectionFunction('filter_input');
/* Output:
Function [ <internal:filter> function filter_input ] {
}
*/