<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                >報告了一個類的有關信息 ``` ReflectionClass implements Reflector { /* 常量 */ const integer IS_IMPLICIT_ABSTRACT = 16;//指示了類是一個抽象類(abstract), 因為它有抽象(abstract)方法 const integer IS_EXPLICIT_ABSTRACT = 32 ;//指示了類是一個抽象類(abstract), 因為它已明確定義。 const integer IS_FINAL = 64 ;//指示這是一個 final 類.//類的名稱。只讀,并在嘗試賦值的時候會拋出 ReflectionException /* 屬性 */ public $name ; /* 方法 */ public __construct ( mixed $argument ) //初始化 ReflectionClass 類 public static export ( mixed $argument [, bool $return = false ] ) : string //導出一個類 public getConstant ( string $name ) : mixed //獲取定義過的一個常量 public getConstants ( void ) : array//獲取一組常量 public getConstructor ( void ) : ReflectionMethod//獲取類的構造函數 public getDefaultProperties ( void ) : array //獲取默認屬性 public getDocComment ( void ) : string //獲取文檔注釋 public getEndLine ( void ) : int //獲取最后一行的行數 public getExtension ( void ) : ReflectionExtension //根據已定義的類獲取所在擴展的 ReflectionExtension 對象 public getExtensionName ( void ) : string //獲取定義的類所在的擴展的名稱 public getFileName ( void ) : string //獲取定義類的文件名 public getInterfaceNames ( void ) : array //獲取接口(interface)名稱 public getInterfaces ( void ) : array //獲取接口 public getMethod ( string $name ) : ReflectionMethod //獲取一個類方法的 ReflectionMethod public getMethods ([ int $filter ] ) : array //獲取所有方法組成的數組 public getModifiers ( void ) : int //獲取類的修飾符 public getName ( void ) : string //獲取類名 public getNamespaceName ( void ) : string //獲取命名空間的名稱 public getParentClass ( void ) : ReflectionClass //獲取父類 public getProperties ([ int $filter ] ) : array //獲取一組屬性 public getProperty ( string $name ) : ReflectionProperty //獲取類的一個屬性的 ReflectionProperty public getReflectionConstant ( string $name ) : ReflectionClassConstant //獲取類的常量的ReflectionClassConstant public getReflectionConstants ( void ) : array //獲取類常量 public getShortName ( void ) : string //獲取短名 public getStartLine ( void ) : int //獲取起始行號 public getStaticProperties ( void ) : array //獲取靜態(static)屬性 public getStaticPropertyValue ( string $name [, mixed &$def_value ] ) : mixed //獲取靜態(static)屬性的值 public getTraitAliases ( void ) : array //返回 trait 別名的一個數組 public getTraitNames ( void ) : array //返回這個類所使用 traits 的名稱的數組 public getTraits ( void ) : array //返回這個類所使用的 traits 數組 public hasConstant ( string $name ) : bool //檢查常量是否已經定義 public hasMethod ( string $name ) : bool //檢查方法是否已定義 public hasProperty ( string $name ) : bool //檢查屬性是否已定義 public implementsInterface ( string $interface ) : bool //接口的實現 public inNamespace ( void ) : bool //檢查是否位于命名空間中 public isAbstract ( void ) : bool //檢查類是否是抽象類(abstract) public isAnonymous ( void ) : bool //檢查類是否是匿名類 public isCloneable ( void ) : bool //返回了一個類是否可復制 public isFinal ( void ) : bool //檢查類是否聲明為 final public isInstance ( object $object ) : bool //檢查類的實例 public isInstantiable ( void ) : bool //檢查類是否可實例化 public isInterface ( void ) : bool //檢查類是否是一個接口(interface) public isInternal ( void ) : bool //檢查類是否由擴展或核心在內部定義 public isIterable ( void ) : bool //檢查此類是否可迭代 public isIterateable ( void ) : bool //檢查是否可迭代(iterateable) public isSubclassOf ( string $class ) : bool //檢查是否為一個子類 public isTrait ( void ) : bool //返回了是否為一個 trait public isUserDefined ( void ) : bool //檢查是否由用戶定義的 public newInstance ( mixed $args [, mixed $... ] ) : object //創建類的新的實例。給出的參數將會傳遞到類的構造函數。接受可變數目的參數,用于傳遞到類的構造函數,和call_user_func()很相似 public newInstanceArgs ([ array $args ] ) : object //從給出的參數創建一個新的類實例,給出的參數將傳遞到類的構造函數 public newInstanceWithoutConstructor ( void ) : object //創建一個新的類實例而不調用它的構造函數 public setStaticPropertyValue ( string $name , string $value ) : void //設置靜態屬性的值 public __toString ( void ) : strin //返回 ReflectionClass 對象字符串的表示形式 } ``` # **例子:** ## **檢查類** ``` function classData(ReflectionClass $class) { $details = ''; $name = $class->getName(); // 返回要檢查的類名 if ($class->isUserDefined()) { // 檢查類是否由用戶定義 $details .= "$name 類是用戶自定義的" . PHP_EOL; } if ($class->isInternal()) { // 檢查類是否由擴展或核心在內部定義 $details .= "$name is built-in" . PHP_EOL; } if ($class->isInterface()) { // 檢查類是否是一個接口 $details .= "$name 是一個接口類" . PHP_EOL; } if ($class->isAbstract()) { // 檢查類是否是抽象類 $details .= "$name 是一個抽象類" . PHP_EOL; } if ($class->isFinal()) { // 檢查類是否聲明為 final $details .= "$name 是一個final類" . PHP_EOL; } if ($class->isInstantiable()) { // 檢查類是否可實例化 $details .= "$name 類可以被實例化" . PHP_EOL; } else { $details .= "$name 類不能實例化" . PHP_EOL; } return $details; } $prodClass = new ReflectionClass('User'); print classData($prodClass); ``` ## **獲取內容信息** ``` function getClassSource(ReflectionClass $class) { $path = $class->getFileName(); // 獲取類文件的絕對路徑 $lines = @file($path); // 由路徑獲得由文件中所有行組成的數組(包括User以外的整個文件內容) $from = $class->getStartLine(); // 提供類的起始行 $to = $class->getEndLine(); // 提供類的終止行 $len = $to - $from + 1; return implode(array_slice($lines, $from - 1, $len));//提取User類部分并將此數組拼接為字符串 } $prodClass = new ReflectionClass('User'); var_dump(getClassSource($prodClass)); ``` ## **# 檢查方法** >[info]* 獲得?ReflectionFunctionAbstract 下的ReflectionMethod 對象的方法有兩種:第一種是通過?ReflectionClass::getMethods() 獲得 ReflectionMethod 對象的數組,會返回類中所有方法的?ReflectionMethod??對象。無需知道方法名 >* 第二種是直接使用 ReflectionMethod??類實例化對象:`new ReflectionMethod('User', 'getName');`,這種方式只能獲取一個類方法對象,需要提前知道方法名。 ReflectionMethod 對象的方法例子參考下節的ReflectionMethod類 ``` //調用B的show方法時候去調用A的show方法 class A{ function show($param=20){ echo "classA的show方法,參數值為{$param}"; } } class B{ private $obj; function __construct(){ $this->obj = new A(); } function __call($name, $arguments) { $ref = new ReflectionClass($this->obj); //檢查方法是否已定義 if ($ref->hasMethod($name)){ //獲取一個類方法的 ReflectionMethod對象。相當于new ReflectionMethod('class', 'myMethod') $method = $ref->getMethod($name); if ($method->isPublic()&&!$method->isAbstract()&&count($arguments)==0){ if ($method->isStatic()){ //如果是靜態方法,不需要傳入調用的對象 $method->invoke(null); }else{ $method->invoke($this->obj); } }else{ if ($method->isStatic()){ //如果是靜態方法,不需要傳入調用的對象 $method->invokeArgs(null,$arguments); }else{ $method->invokeArgs($this->obj,$arguments); } } } } } $b=new B(); $b->show();//classA的show方法,參數值為20 $b->show(21);//classA的show方法,參數值為21 ``` 插件案例 ~~~ include_once __DIR__."/plugin.php"; function get_plugin_menus(){ $menus = array(); $all_class = get_declared_classes();//獲取所有的類 foreach ($all_class as $cls){ $ref_cls = new ReflectionClass($cls); if ($ref_cls->implementsInterface('Plugin')){//是否實現了某個接口 if ($ref_cls->hasMethod('showMenu')){ $method = $ref_cls->getMethod("showMenu"); if ($method->isStatic()){ $method->invoke(null); } else{ //$method->invoke(new $cls());//這樣獲取類 $instance = $ref_cls->newInstance(); $menu = $method->invoke($instance); } } } $menus = array_merge($menus,$menu); } return $menus; } echo "<pre>";get_plugin_menus();echo "<pre>"; interface Plugin{ function showMenu(); } class MyPlugin implements Plugin{ function showMenu() { $menu = array( array( 'name' => 'menu1', 'link' => 'index.php?act=link1' ), array( 'name' => 'menu2', 'link' => 'index.php?act=link2' ) ); return $menu; } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看