国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

PHP變量與類型擴展之反射及其使用

瀏覽:3日期:2022-09-16 09:32:38
一、概述與安裝

PHP 5 具有完整的反射 API,添加了對類、接口、函數、方法和擴展進行反向工程的能力。 此外,反射 API 提供了方法來取出函數、類和方法中的文檔注釋。

請注意部分內部?API?丟失了反射擴展工作所需的代碼。 例如,一個內置的 PHP 類可能丟失了反射屬性的數據。這些少數的情況被認為是錯誤,不過, 正因為如此,它們應該被發現和修復。

使用這些函數不需要安裝,它們是 PHP 核心的一部分。

二、使用范例

在反射文檔中存在很多例子,通常位于每個類的 __construct 文檔中。

Example ?Shell 里的一個反射例子(一個終端)

$ php --rf strlen$ php --rc finfo$ php --re json$ php --ri dom

以上例程的輸出類似于:

Function [ <internal:Core> function strlen ] { - Parameters [1] { Parameter #0 [ <required> $str ] }}Class [ <internal:fileinfo> class finfo ] { - Constants [0] { } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [4] { Method [ <internal:fileinfo, ctor> public method finfo ] { - Parameters [2] {Parameter #0 [ <optional> $options ]Parameter #1 [ <optional> $arg ] } } Method [ <internal:fileinfo> public method set_flags ] { - Parameters [1] {Parameter #0 [ <required> $options ] } } Method [ <internal:fileinfo> public method file ] { - Parameters [3] {Parameter #0 [ <required> $filename ]Parameter #1 [ <optional> $options ]Parameter #2 [ <optional> $context ] } } Method [ <internal:fileinfo> public method buffer ] { - Parameters [3] {Parameter #0 [ <required> $string ]Parameter #1 [ <optional> $options ]Parameter #2 [ <optional> $context ] } } }}Extension [ <persistent> extension #23 json version 1.2.1 ] { - Constants [10] { Constant [ integer JSON_HEX_TAG ] { 1 } Constant [ integer JSON_HEX_AMP ] { 2 } Constant [ integer JSON_HEX_APOS ] { 4 } Constant [ integer JSON_HEX_QUOT ] { 8 } Constant [ integer JSON_FORCE_OBJECT ] { 16 } Constant [ integer JSON_ERROR_NONE ] { 0 } Constant [ integer JSON_ERROR_DEPTH ] { 1 } Constant [ integer JSON_ERROR_STATE_MISMATCH ] { 2 } Constant [ integer JSON_ERROR_CTRL_CHAR ] { 3 } Constant [ integer JSON_ERROR_SYNTAX ] { 4 } } - Functions { Function [ <internal:json> function json_encode ] { - Parameters [2] {Parameter #0 [ <required> $value ]Parameter #1 [ <optional> $options ] } } Function [ <internal:json> function json_decode ] { - Parameters [3] {Parameter #0 [ <required> $json ]Parameter #1 [ <optional> $assoc ]Parameter #2 [ <optional> $depth ] } } Function [ <internal:json> function json_last_error ] { - Parameters [0] { } } }}domDOM/XML => enabledDOM/XML API Version => 20031129libxml Version => 2.7.3HTML Support => enabledXPath Support => enabledXPointer Support => enabledSchema Support => enabledRelaxNG Support => enabled三、相關擴展

如果你想創建內建類的專門版本(比如說,在創建并導出高亮 HTML 時,以易于訪問的成員變量來取代方法或使用實用的方法), 你可以繼續并擴展它們。

Example #1 擴展內置的類

<?php/** * My Reflection_Method class */class My_Reflection_Method extends ReflectionMethod{ public $visibility = array();

public function __construct($o, $m) { parent::__construct($o, $m); $this->visibility = Reflection::getModifierNames($this->getModifiers()); }}/** * Demo class #1 * */class T { protected function x() {}}/** * Demo class #2 * */class U extends T { function x() {}}// 輸出信息var_dump(new My_Reflection_Method(’U’, ’x’));?>

以上例程的輸出類似于:

object(My_Reflection_Method)#1 (3) { ['visibility']=> array(1) { [0]=> string(6) 'public' } ['name']=> string(1) 'x' ['class']=> string(1) 'U'}

如果你重寫了構造函數,記住在寫任何插入的代碼之前要先調用父類的構造函數。 不這么做將會導致以下的結果:?Fatal error: Internal error: Failed to retrieve the reflection object

四、反射類

Reflection?— Reflection 類

ReflectionClass?— ReflectionClass 類

ReflectionZendExtension?— ReflectionZendExtension 類

ReflectionExtension?— ReflectionExtension 類

ReflectionFunction?— ReflectionFunction 類

ReflectionFunctionAbstract?— ReflectionFunctionAbstract 類

ReflectionMethod?— ReflectionMethod 類

ReflectionObject?— ReflectionObject 類

ReflectionParameter?— ReflectionParameter 類

ReflectionProperty?— ReflectionProperty 類

Reflector?— Reflector 接口

ReflectionException?— ReflectionException 類

標簽: PHP
相關文章:
主站蜘蛛池模板: 国产亚洲一区二区精品 | 亚洲伊人色综合网站亚洲伊人 | 毛片久久| 国产麻豆一级在线观看 | 精品国产欧美一区二区五十路 | 一区二区三区不卡在线 | 99香蕉网 | 综合亚洲精品一区二区三区 | 国产精品v免费视频 | 日本高清免费视频www | 亚洲女人被黑人猛躁进女人 | 久久99精品这里精品3 | 精品国产午夜久久久久九九 | 女高中生被cao到哭视频 | 久久亚洲精品无码观看不卡 | 久久成人动漫 | 亚洲欧美精品一区二区 | 亚洲精品欧美精品 | 国产一级视频在线观看 | 免费黄色在线网址 | 欧美日本一道道一区二区三 | 日本女人www | 9久久免费国产精品特黄 | 九草在线 | 国产深夜福利视频网站在线观看 | 国产在线拍揄自揄视精品不卡 | 男子操女子 | 俺来也俺来也天天夜夜视频 | 国产大片在线看 | 美女亚洲综合 | 真人一级一级特黄高清毛片 | 久久国产精品久久久久久久久久 | 欧美一级日韩在线观看 | 久久久久久久久久久大尺度免费视频 | 亚洲国产精品一区二区久久 | 大学生一级一片第一次免费 | 台湾三级| 国产乱理片在线观看夜 | 久久99亚洲精品久久频 | 神马午夜在线 | 日本一区二区三区精品视频 |