zoukankan      html  css  js  c++  java
  • ReflectionClass与Closure

    <?php
    /**
     * Class A
     */
    class A{
    
    }
    
    
    $obj = new ReflectionClass('A');
    var_export($obj.PHP_EOL);
    

    类后面加上PHP_EOL会把当前类的详细接口文档打印出来。

    ReflectionClass 可以利用这个动态创建类,动态使用类方法参数。

    try{
    //如果存在控制器名字的类
    if(class_exists($this->getController())) {
    //利用反射api构造一个控制器类对应的反射类
    $rc = new ReflectionClass($this->getController());
    //如果该类实现 了IController接口
    if($rc->implementsInterface('IController')) {
    //该类拥有解析后的action字符串所指向的方法名
    if($rc->hasMethod($this->getAction())) {
    //构造一个控制器类的实例
    $controller = $rc->newInstance();
    //获取该类$action参数所指向的方法对象
    $method = $rc->getMethod($this->getAction());
    //反射类方法对象的调用方式:
    $method->invoke($controller);
    } else {
    //以下为可能抛出异常
    throw new Exception("Action");
    }
    } else {
    throw new Exception("Interface");
    }
    } else {
    throw new Exception("Controller");
    }
        }catch(exception $e)
        {
            echo $e;
        }
    
    

    Closure //闭包的意思。这个跟javascript的闭包有点类似。

    function getClosure(){
    return function(){};
    }
    var_dump(getClosure());//可以看到是一个 Closure Object
    
  • 相关阅读:
    bae问题
    union intersect minus
    在搭建SpringMvc Hibernate框架时遇到的问题
    详细解读Spring2.5 +Struts1.3 框架(使用Spring声明式事物管理和springjjdbc模板)
    javaee缓存技术 oscache ehcache
    Warning
    Math
    Test
    网络流24题-最小路径覆盖问题
    Wannafly summer camp Day3--Knight
  • 原文地址:https://www.cnblogs.com/canbefree/p/5212531.html
Copyright © 2011-2022 走看看