《PHP實例:php面向對象之反射功能與用法分析》要點:
本文介紹了PHP實例:php面向對象之反射功能與用法分析,希望對您有用。如果有疑問,可以聯系我們。
本文實例講述了php面向對象之反射功能與用法.分享給大家供大家參考,具體如下:PHP教程
個人對反射定義的理解:PHP教程
首先得說說什么叫反射.對于一個新手來說,反射這個概念常常給人一種似懂非懂的 感覺,不知道該如何下手操作.PHP教程
反射是指:指在PHP運行狀態中,擴展分析PHP程序,導出或提取出關于類、方法、屬性、參數等的詳細信息,同時也包括注釋.這種動態獲取的信息以及動態調用對象的方法 的功能稱為反射API.反射是操縱面向對象范型中元模型的API,其功能十分強大,可幫助我們構建復雜,可擴展的應用.(注意:php中這種反向操作,實在PHP5之后才完全具備)PHP教程
下面在此我用實例進行說明:PHP教程
class test{ private $A; public $B; protected $C; public function test(){ return "this is a test function"; } } //實例化一個反射類ReflectionClass $obj=new ReflectionClass('test'); echo $obj."<br>"; //實例化test類,并訪問其test方法 $obj2=$obj->newInstance(); echo $obj2->test();
個人實例返回結果:PHP教程
/** * xxx.php * ============================================== * Copy right 2012-2015 * ---------------------------------------------- * This is not a free software, without any authorization is not allowed to use and spread. * ============================================== * @Author:YeXianMing * @Email:LangWaiShiGe@hotmail.com * @Version:zend studio10.6.2 php5.4.38 apache2.2 */ Class [ class test ] { @@ D:\www\MyProjecttest\index5.php 13-21 - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [3] { Property [ private $A ] Property [ public $B ] Property [ protected $C ] } - Methods [1] { Method [ public method test ] { @@ D:\www\MyProjecttest\index5.php 18 - 20 } } } this is a test function
更多關于PHP相關內容感興趣的讀者可查看本站專題:《php面向對象程序設計入門教程》、《PHP基本語法入門教程》、《PHP運算與運算符用法總結》、《PHP網絡編程技巧總結》、《PHP數組(Array)操作技巧大全》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》PHP教程
希望本文所述對大家PHP程序設計有所幫助.PHP教程
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/1302.html