這篇文章主要介紹了PHP Reflection API詳解,本文講解了Reflection類、ReflectionException類、ReflectionFunction類、ReflectionParameter類、ReflectionClass類、ReflectionMethod類等內容,需要的朋友可以參考下
PHP Reflection API是PHP5才有的新功能,它是用來導出或提取出關于類、方法、屬性、參數等的詳細信息,包括注釋。
PHP Reflection API有:
?
1 2 3 4 5 6 7 8 9 10 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 { }具體API說明:
①Reflection類
?
1 2 3 4 5 6 7 8 9 <?php class Reflection { public static mixed export(Reflector r [,bool return]) //導出一個類或方法的詳細信息 public static array getModifierNames(int modifiers) //取得修飾符的名字 }②ReflectionException類
該類繼承標準類,沒特殊方法和屬性。
③ReflectionFunction類
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 <?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() //取得該方法所需的參數個數 } ?>新聞熱點
疑難解答