• PHP 反射类的简单使用!


      公司项目中用到了反射类,它的作用是可以把灵活的传过来的类名通过映射里面的方法实现框架模块搭建!使用方法总结为下面几步:

        第一步:

           //传类名过来映射
                $this->_configClass = new ReflectionClass($this->_configClassName);
                //得到这个类的实例
                $this->_configInstance = $this->_configClass->newInstanceArgs();

        第二步:

           //检测这个类中是否含有这个方法:hasMethod(),注意是原类!如果有则获取它:getMethod(),然后通过原类实例
           化出来的类用:invoke(参数为前面实例化得到的新类)调用即可!
           $this->_includeSourseConfig = ($this->_configClass->hasMethod('_includeSourse')) ? $this->_configClass->getMethod('_includeSourse')->invoke($this->_configInstance) : false;

        这样就搞定了。

  • 相关阅读:
    019-centos的yum用法
    018-DNS解析过程与配置DNS服务
    017-linux正则表达式
    016-sed
    014-配置SSH免密钥登录
    013-安装VNC服务
    012-centos6.5配置静态ip
    010-centos上安装matlab
    mysqlbinlog
    更换mysql数据库的datadir目录
  • 原文地址:https://www.cnblogs.com/lgqtecng/p/6534282.html
Copyright © 2020-2023  润新知