復制代碼 代碼如下:
$uid = $_GET['uid'];$score " /> 果冻传媒在线看免费高清,琪琪色原网站ying,久久黄色网址

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

PHP反射使用實例和PHP反射API的中文說明

最近在開發過程中需要獲取某個類方法的參數數量、名稱及參數順序,好根據參數的名稱來從$_GET里取值。

如方法原型為test($uid,$score), 那么我就知道需要需要從$_GET取
復制代碼 代碼如下:
$uid = $_GET['uid'];

$score = $_GET['score'];

然后調用方法$obj->test($uid,$score)

當然前提是約定好了參數名稱和get方法傳值變量名一致。

采用php的反射API,獲得函數參數名稱和參數默認值的方法如下:
復制代碼 代碼如下:
<?php 
class testClass{ 
     
    public function testFunc($param1,$param2=0){ 
         
    } 

 
$method = new ReflectionMethod('testClass', 'testFunc'); 
$params = $method--->getParameters(); 
foreach ($params as $param) { 
    echo 'param name: ' . $param->getName(),"/n"; 
    if ($param->isOptional()) { 
        echo 'Default value: ' . $param->getDefaultValue(),"/n"; 
    } 

下面是php反射API的介紹:

1、用途:
該擴展分析php程序,導出或提取出關于類、方法、屬性、參數等的詳細信息,包括注釋。
Reflection可以說是對php庫函數:“Classes/Objects 類/對象函數”的一個擴展。
主要用在通過程序檢測現有php程序內部關于類、方法等信息,并做出處理。

2、API概覽:
復制代碼 代碼如下:
class Reflection { } 
interface Reflector { } 
class ReflectionException extends Exception { } 
class ReflectionFunction implements Reflector { } 
class ReflectionParameter implements Reflector { } 
class ReflectionMethod extends ReflectionFunction { } 
class ReflectionClass implements Reflector { } 
class ReflectionObject extends ReflectionClass { } 
class ReflectionProperty implements Reflector { } 
class ReflectionExtension implements Reflector { } 

3、詳細說明:(例子詳見php手冊)
復制代碼 代碼如下:
①Reflection類 
<?php 
class Reflection 

public static mixed export(Reflector r [,bool return]) 
//導出一個類或方法的詳細信息 
public static array getModifierNames(int modifiers) 
//取得修飾符的名字 

?> 
 
②ReflectionException類 
 
該類繼承標準類,沒特殊方法和屬性。 
 
③ReflectionFunction類 
<?php 
class ReflectionFunction implements Reflector 

final private __clone() 
public object __construct(string name) 
public string __toString() 
public static string export() 
//導出該函數的詳細信息 
public string getName() 
//取得函數名 
public bool isInternal() 
//測試是否為系統內部函數 
public bool isUserDefined() 
//測試是否為用戶自定義函數 
public string getFileName() 
//取得文件名,包括路徑名 
public int getStartLine() 
//取得定義函數的起始行 
public int getEndLine() 
//取得定義函數的結束行 
public string getDocComment() 
//取得函數的注釋 
public array getStaticVariables() 
//取得靜態變量 
public mixed invoke(mixed* args) 
//調用該函數,通過參數列表傳參數 
public mixed invokeArgs(array args) 
//調用該函數,通過數組傳參數 
public bool returnsReference() 
//測試該函數是否返回引用 
public ReflectionParameter[] getParameters() 
//取得該方法所需的參數,返回值為對象數組 
public int getNumberOfParameters() 
//取得該方法所需的參數個數 
public int getNumberOfRequiredParameters() 
//取得該方法所需的參數個數 

?> 
 
④ReflectionParameter類: 
<?php 
class ReflectionParameter implements Reflector 

final private __clone() 
public object __construct(string name) 
public string __toString() 
public static string export() 
//導出該參數的詳細信息 
public string getName() 
//取得參數名 
public bool isPassedByReference() 
//測試該參數是否通過引用傳遞參數 
public ReflectionClass getClass() 
//若該參數為對象,返回該對象的類名 
public bool isArray() 
//測試該參數是否為數組類型 
public bool allowsNull() 
//測試該參數是否允許為空 
public bool isOptional() 
//測試該參數是否為可選的,當有默認參數時可選 
public bool isDefaultValueAvailable() 
//測試該參數是否為默認參數 
public mixed getDefaultValue() 
//取得該參數的默認值 

?> 
 
⑤ReflectionClass類: 
<?php 
class ReflectionClass implements Reflector 

final private __clone() 
public object __construct(string name) 
public string __toString() 
public static string export() 
//導出該類的詳細信息 
public string getName() 
//取得類名或接口名 
public bool isInternal() 
//測試該類是否為系統內部類 
public bool isUserDefined() 
//測試該類是否為用戶自定義類 
public bool isInstantiable() 
//測試該類是否被實例化過 
public bool hasConstant(string name) 
//測試該類是否有特定的常量 
public bool hasMethod(string name) 
//測試該類是否有特定的方法 
public bool hASProperty(string name) 
//測試該類是否有特定的屬性 
public string getFileName() 
//取得定義該類的文件名,包括路徑名 
public int getStartLine() 
//取得定義該類的開始行 
public int getEndLine() 
//取得定義該類的結束行 
public string getDocComment() 
//取得該類的注釋 
public ReflectionMethod getConstructor() 
//取得該類的構造函數信息 
public ReflectionMethod getMethod(string name) 
//取得該類的某個特定的方法信息 
public ReflectionMethod[] getMethods() 
//取得該類的所有的方法信息 
public ReflectionProperty getProperty(string name) 
//取得某個特定的屬性信息 
public ReflectionProperty[] getProperties() 
//取得該類的所有屬性信息 
public array getConstants() 
//取得該類所有常量信息 
public mixed getConstant(string name) 
//取得該類特定常量信息 
public ReflectionClass[] getInterfaces() 
//取得接口類信息 
public bool isInterface() 
//測試該類是否為接口 
public bool isAbstract() 
//測試該類是否為抽象類 
public bool isFinal() 
//測試該類是否聲明為final 
public int getModifiers() 
//取得該類的修飾符,返回值類型可能是個資源類型 
//通過Reflection::getModifierNames($class->getModifiers())進一步讀取 
public bool isInstance(stdclass object) 
//測試傳入的對象是否為該類的一個實例 
public stdclass newInstance(mixed* args) 
//創建該類實例 
public ReflectionClass getParentClass() 
//取得父類 
public bool isSubclassOf(ReflectionClass class) 
//測試傳入的類是否為該類的父類 
public array getStaticProperties() 
//取得該類的所有靜態屬性 
public mixed getStaticPropertyValue(string name [, mixed default]) 
//取得該類的靜態屬性值,若private,則不可訪問 
public void setStaticPropertyValue(string name, mixed value) 
//設置該類的靜態屬性值,若private,則不可訪問,有悖封裝原則 
public array getDefaultProperties() 
//取得該類的屬性信息,不含靜態屬性 
public bool isIterateable() 
public bool implementsInterface(string name) 
//測試是否實現了某個特定接口 
public ReflectionExtension getExtension() 
public string getExtensionName() 

?> 
 
⑥ReflectionMethod類: 
<?php 
class ReflectionMethod extends ReflectionFunction 

public __construct(mixed class, string name) 
public string __toString() 
public static string export() 
//導出該方法的信息 
public mixed invoke(stdclass object, mixed* args) 
//調用該方法 
public mixed invokeArgs(stdclass object, array args) 
//調用該方法,傳多參數 
public bool isFinal() 
//測試該方法是否為final 
public bool isAbstract() 
//測試該方法是否為abstract 
public bool isPublic() 
//測試該方法是否為public 
public bool isPrivate() 
//測試該方法是否為private 
public bool isProtected() 
//測試該方法是否為protected 
public bool isStatic() 
//測試該方法是否為static 
public bool isConstructor() 
//測試該方法是否為構造函數 
public bool isDestructor() 
//測試該方法是否為析構函數 
public int getModifiers() 
//取得該方法的修飾符 
public ReflectionClass getDeclaringClass() 
//取得該方法所屬的類 
// Inherited from ReflectionFunction 
final private __clone() 
public string getName() 
public bool isInternal() 
public bool isUserDefined() 
public string getFileName() 
public int getStartLine() 
public int getEndLine() 
public string getDocComment() 
public array getStaticVariables() 
public bool returnsReference() 
public ReflectionParameter[] getParameters() 
public int getNumberOfParameters() 
public int getNumberOfRequiredParameters() 

?> 
 
⑦ReflectionProperty類: 
<?php 
class ReflectionProperty implements Reflector 

final private __clone() 
public __construct(mixed class, string name) 
public string __toString() 
public static string export() 
//導出該屬性的詳細信息 
public string getName() 
//取得該屬性名 
public bool isPublic() 
//測試該屬性名是否為public 
public bool isPrivate() 
//測試該屬性名是否為private 
public bool isProtected() 
//測試該屬性名是否為protected 
public bool isStatic() 
//測試該屬性名是否為static 
public bool isDefault() 
public int getModifiers() 
//取得修飾符 
public mixed getValue(stdclass object) 
//取得該屬性值 
public void setValue(stdclass object, mixed value) 
//設置該屬性值 
public ReflectionClass getDeclaringClass() 
//取得定義該屬性的類 
public string getDocComment() 
//取得該屬性的注釋 

?> 
 
⑧ReflectionExtension類 
<?php 
class ReflectionExtension implements Reflector { 
final private __clone() 
public __construct(string name) 
public string __toString() 
 
public static string export() 
//導出該擴展的所有信息 
public string getName() 
//取得該擴展的名字 
public string getVersion() 
//取得該擴展的版本 
public ReflectionFunction[] getFunctions() 
//取得該擴展的所有函數 
public array getConstants() 
//取得該擴展的所有常量 
public array getINIEntries() 
//取得與該擴展相關的,在php.ini中的指令信息 
public ReflectionClass[] getClasses() 
public array getClassNames() 

?> 

php技術PHP反射使用實例和PHP反射API的中文說明,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 杨幂视频1分11未删减在线观看 | 97视频在线免费播放 | 天堂tv免费tv在线tv香蕉 | 亚洲AV无码乱码在线观看浪潮 | 青柠在线观看免费高清电视剧荣耀 | 亚洲精品网址 | 99久久亚洲精品日本无码 | 蜜臀AV熟女人妻中文字幕 | 国产毛多水多高潮高清 | 97色伦97色伦国产 | 青草精品国产福利在线视频 | 在线自拍亚洲视频欧美 | 亚洲性无码av在线 | 奇米网一区二区三区在线观看 | 99er4久久视频精品首页 | 国产亚洲精品久久久久久无码网站 | 超清无码波多野吉衣与黑人 | 亚洲欧洲日韩视频在钱 | 久久这里的只有是精品23 | 暗卫受被肉到失禁各种PLAY | 九九视频在线观看视频6 | 国产毛A片久久久久久无码 国产毛A片啊久久久久久A | 亚洲、国产综合视频 | 色哒哒影院| 久久亚洲国产成人影院 | 看电影来5566一区.二区 | 99精品热视频30在线热视频 | 99福利视频 | 日本一卡二卡三卡四卡无卡免费播放 | 99久久婷婷国产麻豆精品电影 | 一本之道高清视频在线观看 | 菠萝菠萝蜜视频在线看1 | 99精品欧美一区二区三区美图 | 国产精品系列在线一区 | 亚洲国产精品久久人人爱 | 国产中文字幕乱码免费 | 久久免费看少妇高潮A片特爽 | 影视先锋男人无码在线 | 久久99热成人精品国产 | 乳交高H糙汉宠文 | 久久久免费观看 |