<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                >[info]PHP 5 具有完整的反射 API,添加了對類、接口、函數、方法和擴展進行*反向工程*的能力。 此外,反射 API 提供了方法來取出函數、類和方法中的文檔注釋。 就算是類成員定義為private也可以在外部訪問,不用創建類的實例也可以訪問類的成員和方法 ## **反射類型** PHP反射API會基于類,方法,屬性,參數等維護相應的反射類,已提供相應的調用API。 | 類型 | 說明 | | --- | --- | | Reflector | Reflector 是一個接口,被所有可導出的反射類所實現(implement) | | Reflection | 反射(reflection)類 | | ReflectionClass | 報告了一個類的有關信息 | | ReflectionZendExtension | 報告Zend擴展的相關信息 | | ReflectionExtension | 報告了PHP擴展的有關信息 | | ReflectionFunction | 報告了一個函數的有關信息 | | ReflectionFunctionAbstract | ReflectionFunction 的父類 | | ReflectionMethod | 報告了一個方法的有關信息 | | ReflectionObject | 報告了一個對象(object)的相關信息 | | ReflectionParameter | 取回了函數或方法參數的相關信息 | | ReflectionProperty | 報告了類的屬性的相關信息 | ``` <?php class Bar{} $bar=new Bar(); class Foo { const LIKE="football"; public static $name = 'dash'; private static $id = 520; private $age=20; public function __construct(Bar $bar,$a,$b,$c) { //var_dump($bar); } public function say($content){ return (self::$name).'說了:'.$content; } } $reflect_class = new \ReflectionClass('Foo');//ReflectionClass::__set_state(array( 'name' => 'Foo', )) /** * 獲取Foo類的實例 */ //創建類的新的實例。給出的參數將會傳遞到類的構造函數。接受可變數目的參數,用于傳遞到類的構造函數,和call_user_func()很相似 $foo_obj=$reflect_class->newInstance($bar,'__construct_param2','__construct_param3','...');//Foo::__set_state(array( 'age' => 20, )) //從給出的參數創建一個新的類實例,給出的參數將傳遞到類的構造函數 $foo_obj=$reflect_class->newInstanceArgs([$bar,'__construct_param2','__construct_param3','...']);//Foo::__set_state(array( 'age' => 20, )) //創建一個新的類實例而不調用它的構造函數 $foo_obj=$reflect_class->newInstanceWithoutConstructor();//Foo::__set_state(array( 'age' => 20, )) $foo_obj->say('haha');//"dash說了:haha" /** * 獲取類常量的ReflectionClassConstant */ ////獲取一組類常量的ReflectionClassConstant $reflection_constants=$reflect_class->getReflectionConstants();//array ( 0 => ReflectionClassConstant::__set_state(array( 'name' => 'LIKE', 'class' => 'Foo', )), ) //獲取指定常量的ReflectionClassConstant $reflection_constant=$reflect_class->getReflectionConstant('LIKE');//ReflectionClassConstant::__set_state(array( 'name' => 'LIKE', 'class' => 'Foo', )) //獲取由getReflectionConstant指定的LIKE常量的值 $cc=$reflection_constant->getValue();//'football' /** * 獲取類屬性的ReflectionProperty */ //獲取類屬性組成的數組 $reflected_propertys = $reflect_class->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);//array ( 0 => ReflectionProperty::__set_state(array( 'name' => 'name', 'class' => 'Foo', )), ) //獲取Foo類指定屬性 $reflected_property = $reflect_class->getProperty('age');//ReflectionProperty::__set_state(array( 'name' => 'age', 'class' => 'Foo', )) //設置靜態屬性的值 $reflect_class->setStaticPropertyValue('name', 'tom'); //在非公共的靜態屬性上調用此方法將返回一個ReflectionException,聲明該屬性不存在。 //$reflect_class->setStaticPropertyValue('id', 510);//會報the property does not exist的錯 //用下面的方法繞過上面的報錯問題 $reflected_property = $reflect_class->getProperty('id');//ReflectionProperty::__set_state(array( 'name' => 'id', 'class' => 'Foo', )) $reflected_property->setAccessible(true);//設置方法是否訪問 //設置屬性的值 $reflected_property->setValue(530); /** * 獲取Foo類的方法ReflectionMethod */ //返回Foo類方法組成的信息數組 $reflect_methods=$reflect_class->getMethods();//array ( 0 => ReflectionMethod::__set_state(array( 'name' => '__construct', 'class' => 'Foo', )), 1 => ReflectionMethod::__set_state(array( 'name' => 'say', 'class' => 'Foo', )), ) //返回Foo類指定方法的信息 $reflect_method=$reflect_class->getMethod('__construct');//ReflectionMethod::__set_state(array( 'name' => '__construct', 'class' => 'Foo', )) //獲取Foo類的構造函數的ReflectionMethod $reflect_method=$reflect_class->getConstructor(); //ReflectionMethod::__set_state(array( 'name' => '__construct', 'class' => 'Foo', )) /** * 獲取Foo類某個方法的參數ReflectionParameter的數組 */ //返回由該方法參數組成的數組 $reflection_parameter=$reflect_method->getParameters();//array ( 0 => ReflectionParameter::__set_state(array( 'name' => 'bar', )), 1 => ReflectionParameter::__set_state(array( 'name' => 'a', )), 2 => ReflectionParameter::__set_state(array( 'name' => 'b', )), 3 => ReflectionParameter::__set_state(array( 'name' => 'c', )), ) /** * 執行__construct方法 */ $reflect_method->invoke($foo_obj,$bar,'param2','param3','...');//執行Foo類實例且由getMethod指定的方法 $reflect_method->invokeArgs ($foo_obj,[$bar,'param2','param3','...']);//帶參數執行 /** * 執行say方法 */ $reflect_method=$reflect_class->getMethod('say');//ReflectionMethod::__set_state(array( 'name' => 'say', 'class' => 'Foo', )) echo $reflect_method->invoke($foo_obj,'哈哈');//tom說了:哈哈 echo $reflect_method->invokeArgs ($foo_obj,['嘻嘻']);//tom說了:嘻嘻 ```
                  <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>

                              哎呀哎呀视频在线观看