zoukankan      html  css  js  c++  java
  • php反射类

    class Foo
    {
        private function priFunc(){}
        protected function proFunc(){}
        public function pubFunc(){}
    }
     
    function get_class_all_methods($class){
        $r = new ReflectionClass($class);//反射类
        foreach($r->getMethods() as $key=>$methodObj){
            if($methodObj->isPrivate())
                $methods[$key]['type'] = 'private';
            elseif($methodObj->isProtected())
                $methods[$key]['type'] = 'protected';
            else
                $methods[$key]['type'] = 'public';
                $methods[$key]['name'] = $methodObj->name;
                $methods[$key]['class'] = $methodObj->class;
        }
        return $methods;
    }
     
    $methods = get_class_all_methods('Foo');
    var_dump($methods);
    复制代码

    运行结果:

    复制代码
    array(3) {
      [0]=>
      array(3) {
        ["type"]=>
        string(7) "private"
        ["name"]=>
        string(7) "priFunc"
        ["class"]=>
        string(3) "Foo"
      }
      [1]=>
      array(3) {
        ["type"]=>
        string(9) "protected"
        ["name"]=>
        string(7) "proFunc"
        ["class"]=>
        string(3) "Foo"
      }
      [2]=>
      array(3) {
        ["type"]=>
        string(6) "public"
        ["name"]=>
        string(7) "pubFunc"
        ["class"]=>
        string(3) "Foo"
      }
    }
    复制代码
  • 相关阅读:
    springboot初始篇(一)
    SpringBoot使用数据库JdbcTemplate(三)
    java实现分页查询
    设计模式之单例模式
    ❤️考研数学公式❤️
    ❤️图的遍历❤️
    图的存储
    图的基本概念
    森林与二叉树的应用
    树相关的代码题
  • 原文地址:https://www.cnblogs.com/fx2008/p/2975005.html
Copyright © 2011-2022 走看看