PHP: Get method's arguments?

2019-01-30 17:38发布

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

$methods = get_class_methods($object);

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

Is there a function for this?

1条回答
Ridiculous、
2楼-- · 2019-01-30 18:16

You can use reflection...

$r = new ReflectionMethod($className, $methodName);
$params = $r->getParameters();
foreach ($params as $param) {
    //$param is an instance of ReflectionParameter
    echo $param->getName();
    echo $param->isOptional();
}
查看更多
登录 后发表回答