国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

PHP 反射(Reflection)使用實例

2020-03-22 19:35:09
字體:
來源:轉載
供稿:網友
PHP Reflection是用于獲取類、擴展、方法、函數、對象、參數、屬性的詳細信息。
ReflectionClass類獲取類相關信息,如獲取屬性、方法、文檔注釋等。html' target='_blank'>class Person { * For the sake of demonstration, we"re setting this private private $_allowDynamicAttributes = false; /** type=primary_autoincrement */ protected $id = 0; /** type=varchar length=255 null */ protected $name; /** type=text null */ protected $biography; public function getId() return $this- public function setId($v) $this- id = $v; public function getName() return $this- name; public function setName($v) $this- name = $v; public function getBiography() return $this- biography; public function setBiography($v) $this- biography = $v;//導出類ReflectionClass::export('Person');$r = new ReflectionClass('Person');//獲取所有屬性print_r($r- getProperties()); * 獲取指定屬性 * ReflectionProperty::IS_STATIC * ReflectionProperty::IS_PUBLIC * ReflectionProperty::IS_PROTECTED * ReflectionProperty::IS_PRIVATEprint_r($r- getProperties(ReflectionProperty::IS_PRIVATE));//獲取注釋print_r($r- getProperty('id')- getDocComment());//獲取方法print_r($r- getMethods());ReflectionExtension 類用于獲取擴展相關信息$re = new ReflectionExtension('Reflection');print_r($re- getClasses()); //擴展的所有類print_r($re- getClassNames()); //擴展所有類名$dom = new ReflectionExtension('mysql');print_r($dom- getConstants());//擴展常量print_r($dom- getDependencies());//該擴展依賴print_r($dom- getFunctions());//擴展方法print_r($dom- getINIEntries());//擴展ini信息print_r($dom- getName());//擴展名稱print_r($dom- getVersion());//擴展版本print_r($dom- info());//擴展信息print_r($dom- isPersistent());//是否是持久擴展print_r($dom- isTemporary()); //是否是臨時擴展ReflectionFunction類 用戶獲取函數相關信息$rf = new ReflectionFunction('array_merge');foreach($rf- getParameters() as $item) { echo $item . PHP_EOL;}ReflectionMethod類用戶獲取方法相關信息class Person { public $name; * get name of person public function getName() return $this- name; public function setName($v) $this- name = $v;$rm = new ReflectionMethod('Person', 'getName');print_r($rm- isPublic());print_r($rm- getDocComment());ReflectionObject 類 用于獲取對象相關信息
class Person { public $name; public function __construct($name) $this- name = $name; public function getName() return $this- name; public function setName($v) $this- name = $v;$a = new Person('a');$ro = new ReflectionObject($a);print_r($ro- getMethods());ReflectionParameter 獲取函數或方法參數的相關信息。
class Person { public $name; public function __construct($name) $this- name = $name; public function getName() return $this- name; public function setName($v) $this- name = $v;$p = new ReflectionParameter(array('Person', 'setName'), 0);print_r($p- getPosition()); //0print_r($p- getName()); //vReflectionProperty 獲取類的屬性的相關信息。
class Person { /** 測試 */ public $name; public function __construct($name) $this- name = $name; public function getName() return $this- name; public function setName($v) $this- name = $v;$p = new ReflectionProperty('Person', 'name');print_r($p- getDocComment());PHP教程

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汉川市| 丰顺县| 佛坪县| 称多县| 穆棱市| 浮梁县| 浦城县| 托克逊县| 石楼县| 阳春市| 肃北| 定陶县| 英吉沙县| 中西区| 彭阳县| 资中县| 界首市| 大同县| 治多县| 富锦市| 凤翔县| 洞头县| 汉寿县| 临沧市| 阿勒泰市| 琼海市| 长武县| 高清| 崇礼县| 菏泽市| 普陀区| 准格尔旗| 肥乡县| 赤水市| 长沙市| 二连浩特市| 驻马店市| 沈阳市| 荆州市| 金乡县| 深泽县|