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

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

PHP變量與類(lèi)型擴(kuò)展之反射及其使用

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

PHP 5 具有完整的反射 API,添加了對(duì)類(lèi)、接口、函數(shù)、方法和擴(kuò)展進(jìn)行反向工程的能力。 此外,反射 API 提供了方法來(lái)取出函數(shù)、類(lèi)和方法中的文檔注釋。

請(qǐng)注意部分內(nèi)部?API?丟失了反射擴(kuò)展工作所需的代碼。 例如,一個(gè)內(nèi)置的 PHP 類(lèi)可能丟失了反射屬性的數(shù)據(jù)。這些少數(shù)的情況被認(rèn)為是錯(cuò)誤,不過(guò), 正因?yàn)槿绱耍鼈儜?yīng)該被發(fā)現(xiàn)和修復(fù)。

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

二、使用范例

在反射文檔中存在很多例子,通常位于每個(gè)類(lèi)的 __construct 文檔中。

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

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

以上例程的輸出類(lèi)似于:

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三、相關(guān)擴(kuò)展

如果你想創(chuàng)建內(nèi)建類(lèi)的專(zhuān)門(mén)版本(比如說(shuō),在創(chuàng)建并導(dǎo)出高亮 HTML 時(shí),以易于訪問(wèn)的成員變量來(lái)取代方法或使用實(shí)用的方法), 你可以繼續(xù)并擴(kuò)展它們。

Example #1 擴(kuò)展內(nèi)置的類(lèi)

<?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’));?>

以上例程的輸出類(lèi)似于:

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

如果你重寫(xiě)了構(gòu)造函數(shù),記住在寫(xiě)任何插入的代碼之前要先調(diào)用父類(lèi)的構(gòu)造函數(shù)。 不這么做將會(huì)導(dǎo)致以下的結(jié)果:?Fatal error: Internal error: Failed to retrieve the reflection object

四、反射類(lèi)

Reflection?— Reflection 類(lèi)

ReflectionClass?— ReflectionClass 類(lèi)

ReflectionZendExtension?— ReflectionZendExtension 類(lèi)

ReflectionExtension?— ReflectionExtension 類(lèi)

ReflectionFunction?— ReflectionFunction 類(lèi)

ReflectionFunctionAbstract?— ReflectionFunctionAbstract 類(lèi)

ReflectionMethod?— ReflectionMethod 類(lèi)

ReflectionObject?— ReflectionObject 類(lèi)

ReflectionParameter?— ReflectionParameter 類(lèi)

ReflectionProperty?— ReflectionProperty 類(lèi)

Reflector?— Reflector 接口

ReflectionException?— ReflectionException 類(lèi)

標(biāo)簽: PHP
相關(guān)文章:
主站蜘蛛池模板: 亚洲高清不卡 | 乱子伦农村xxxx | 成人免费在线视频网 | 国产成人综合91精品 | 理论片中文字幕 | 国产一区在线免费观看 | 一区二区三区国模大胆 | 久久老司机波多野结衣 | 久久精品国产99久久99久久久 | 亚洲欧美日本在线观看 | 一级全免费视频播放 | 欧美xxxx精品另类 | 国产三香港三韩国三级不卡 | 亚洲国产成人久久一区久久 | 亚洲aⅴ| 国产亚洲欧美成人久久片 | 久久成人免费观看草草影院 | 国产伦精品一区二区三区四区 | 一级黄色美女视频 | 深夜国产成人福利在线观看女同 | 曰本人做爰大片免费观看一 | 黑人巨大videos极度另类 | 日日撸夜夜操 | 欧美成人激情在线 | 亚洲精品久久久久中文字幕一区 | 最新最好看免费毛片基地 | 永久黄网站色视频免费网站 | 久久精品国产这里是免费 | 日韩一区二区三区在线 | 欧美一区二区三区在线观看 | 美女视频黄的免费视频网页 | 亚洲国产精品久久久久 | 中文字幕在线乱码不卡区区 | 国产精品日韩专区 | 久久福利网站 | 欧美一区二区三区免费播放 | 久久免视频| 白浆在线视频 | 在线精品视频免费观看 | 欧美高清免费一级在线 | 午夜爽爽爽 |