php反射获取方法中的参数

$reflection = new ReflectionClass ( $class_name );
//获取类中的方法,设置获取public,protected类型方法
$methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC + ReflectionMethod::IS_PROTECTED + ReflectionMethod::IS_PRIVATE);
//遍历所有的方法
foreach ($methods as $method) {
    //获取方法的注释
    $doc = $method->getDocComment();
    
    //获取方法的类型
    $method_flag = $method->isProtected();//还可能是public,protected类型的
    //获取方法的参数
    $params = $method->getParameters();
    
    foreach ($params as $param){
        echo $param->getName();
    }
     
}

  

 

posted @ 2022-04-04 23:49  程序员小艺  阅读(177)  评论(0)    收藏  举报