获取方法的参数?

2021-12-23 00:00:00 class object arguments methods php

我可以像这样检查一个对象的所有可用方法:

I can check all available methods for an object like so:

$methods = get_class_methods($object);

但是我怎样才能看到哪些参数必须发送给这些方法?

But how can I see which arguments have to be sent to these methods?

有这个功能吗?

推荐答案

您可以使用 反射...

$r = new ReflectionMethod($className, $methodName);
$params = $r->getParameters();
foreach ($params as $param) {
    //$param is an instance of ReflectionParameter
    echo $param->getName();
    echo $param->isOptional();
}

相关文章