示例:
文件:\bla\test1.php
class Test { public function Hello($one) { } }
文件:\bla2\test2.php
class World { public function GetNumberOfParameters($class, $method) { // output: number of parameters required of method Hello } }
最佳答案
可以使用反射来获取参数的数量。像这样的东西:
$reflec = new ReflectionClass('Test');
$helloMethod = $reflec->getMethod('Hello');
echo "Number of params is: ".$helloMethod->getNumberOfParameters();
请参见此处:http://php.net/manual/en/class.reflectionclass.php
我会考虑你为什么要这样做。我能想到很少有这种情况有用的。
关于php - 我如何知道另一个类的方法需要多少个参数? PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30846851/