php反射机制
PHP5添加了一项新的功能:Reflection。这个功能使得phper可以reverse-engineer class, interface,function,method and extension。通过PHP代码,就可以得到某object的所有信息,并且可以和它交互。
反射是什么?
它是指在PHP运行状态中,扩展分析PHP程序,导出或提取出关于类、方法、属性、参数等的详细信息,包括注释。这种动态获取的信息以及动态调用对象的方
法的功能称为反射API。反射是操纵面向对象范型中元模型的API,其功能十分强大,可帮助我们构建复杂,可扩展的应用。
其用途如:自动加载插件,自动生成文档,甚至可用来扩充PHP语言。
php反射api由若干类组成,可帮助我们用来访问程序的元数据或者同相关的注释交互。借助反射我们可以获取诸如类实现了那些方法,创建一个类的实例(不同于用new创建),调用一个方法(也不同于常规调用),传递参数,动态调用类的静态方法。
反射api是php内建的oop技术扩展,包括一些类,异常和接口,综合使用他们可用来帮助我们分析其它类,接口,方法,属性,方法和扩展。这些oop扩展被称为反射。
thinkphp框架App.class.php文件里的exec中有用到PHP反射。
具体包含的类和实例可参照手册:函数参考》变量与类型相关扩展》反射:
- Reflection — Reflection 类
- Reflection::export — Exports
- Reflection::getModifierNames — 获取修饰符的名称
- ReflectionClass — ReflectionClass 类
- ReflectionClass::__construct — 构造一个 ReflectionClass 类
- ReflectionClass::export — 导出一个类
- ReflectionClass::getConstant — 获取定义过的一个常量
- ReflectionClass::getConstants — 获取一组常量
- ReflectionClass::getConstructor — 获取类的构造函数
- ReflectionClass::getDefaultProperties — 获取默认属性
- ReflectionClass::getDocComment — 获取文档注释
- ReflectionClass::getEndLine — 获取最后一行的行数
- ReflectionClass::getExtension — 根据已定义的类获取所在扩展的 ReflectionExtension 对象
- ReflectionClass::getExtensionName — 获取定义的类所在的扩展的名称
- ReflectionClass::getFileName — 获取定义类的文件名
- ReflectionClass::getInterfaceNames — 获取接口(interface)名称
- ReflectionClass::getInterfaces — 获取接口
- ReflectionClass::getMethod — 获取一个类方法的 ReflectionMethod。
- ReflectionClass::getMethods — 获取方法的数组
- ReflectionClass::getModifiers — 获取修饰符
- ReflectionClass::getName — 获取类名
- ReflectionClass::getNamespaceName — 获取命名空间的名称
- ReflectionClass::getParentClass — 获取父类
- ReflectionClass::getProperties — 获取一组属性
- ReflectionClass::getProperty — 获取类的一个属性的 ReflectionProperty
- ReflectionClass::getShortName — 获取短名
- ReflectionClass::getStartLine — 获取起始行号
- ReflectionClass::getStaticProperties — 获取静态(static)属性
- ReflectionClass::getStaticPropertyValue — 获取静态(static)属性的值
- ReflectionClass::getTraitAliases — 返回 trait 别名的一个数组
- ReflectionClass::getTraitNames — 返回这个类所使用 traits 的名称的数组
- ReflectionClass::getTraits — 返回这个类所使用的 traits 数组
- ReflectionClass::hasConstant — 检查常量是否已经定义
- ReflectionClass::hasMethod — 检查方法是否已定义
- ReflectionClass::hasProperty — 检查属性是否已定义
- ReflectionClass::implementsInterface — 接口的实现
- ReflectionClass::inNamespace — 检查是否位于命名空间中
- ReflectionClass::isAbstract — 检查类是否是抽象类(abstract)
- ReflectionClass::isCloneable — 返回了一个类是否可复制
- ReflectionClass::isFinal — 检查类是否声明为 final
- ReflectionClass::isInstance — 检查类的实例
- ReflectionClass::isInstantiable — 检查类是否可实例化
- ReflectionClass::isInterface — 检查类是否是一个接口(interface)
- ReflectionClass::isInternal — 检查类是否由扩展或核心在内部定义
- ReflectionClass::isIterateable — 检查是否可迭代(iterateable)
- ReflectionClass::isSubclassOf — 检查是否为一个子类
- ReflectionClass::isTrait — 返回了是否为一个 trait
- ReflectionClass::isUserDefined — 检查是否由用户定义的
- ReflectionClass::newInstance — 从指定的参数创建一个新的类实例
- ReflectionClass::newInstanceArgs — 从给出的参数创建一个新的类实例。
- ReflectionClass::newInstanceWithoutConstructor — 创建一个新的类实例而不调用它的构造函数
- ReflectionClass::setStaticPropertyValue — 设置静态属性的值
- ReflectionClass::__toString — 返回 ReflectionClass 对象字符串的表示形式。
- ReflectionZendExtension — ReflectionZendExtension 类
- ReflectionZendExtension::__clone — Clone handler
- ReflectionZendExtension::__construct — Constructor
- ReflectionZendExtension::export — Export
- ReflectionZendExtension::getAuthor — Gets author
- ReflectionZendExtension::getCopyright — Gets copyright
- ReflectionZendExtension::getName — Gets name
- ReflectionZendExtension::getURL — Gets URL
- ReflectionZendExtension::getVersion — Gets version
- ReflectionZendExtension::__toString — To string handler
- ReflectionExtension — ReflectionExtension 类
- ReflectionExtension::__clone — Clones
- ReflectionExtension::__construct — Constructs a ReflectionExtension
- ReflectionExtension::export — Export
- ReflectionExtension::getClasses — Gets classes
- ReflectionExtension::getClassNames — Gets class names
- ReflectionExtension::getConstants — Gets constants
- ReflectionExtension::getDependencies — Gets dependencies
- ReflectionExtension::getFunctions — Gets extension functions
- ReflectionExtension::getINIEntries — Gets extension ini entries
- ReflectionExtension::getName — Gets extension name
- ReflectionExtension::getVersion — Gets extension version
- ReflectionExtension::info — Print extension info
- ReflectionExtension::isPersistent — Returns whether this extension is persistent
- ReflectionExtension::isTemporary — Returns whether this extension is temporary
- ReflectionExtension::__toString — To string
- ReflectionFunction — ReflectionFunction 类
- ReflectionFunction::__construct — Constructs a ReflectionFunction object
- ReflectionFunction::export — Exports function
- ReflectionFunction::getClosure — Returns a dynamically created closure for the function
- ReflectionFunction::invoke — Invokes function
- ReflectionFunction::invokeArgs — Invokes function args
- ReflectionFunction::isDisabled — Checks if function is disabled
- ReflectionFunction::__toString — To string
- ReflectionFunctionAbstract — ReflectionFunctionAbstract 类
- ReflectionFunctionAbstract::__clone — 复制函数
- ReflectionFunctionAbstract::getClosureScopeClass — Returns the scope associated to the closure
- ReflectionFunctionAbstract::getClosureThis — 返回本身的匿名函数
- ReflectionFunctionAbstract::getDocComment — 获取注释内容
- ReflectionFunctionAbstract::getEndLine — 获取结束行号
- ReflectionFunctionAbstract::getExtension — 获取扩展信息
- ReflectionFunctionAbstract::getExtensionName — 获取扩展名称
- ReflectionFunctionAbstract::getFileName — 获取文件名称
- ReflectionFunctionAbstract::getName — 获取函数名称
- ReflectionFunctionAbstract::getNamespaceName — 获取命名空间
- ReflectionFunctionAbstract::getNumberOfParameters — 获取参数数目
- ReflectionFunctionAbstract::getNumberOfRequiredParameters — 获取必须输入参数个数
- ReflectionFunctionAbstract::getParameters — 获取参数
- ReflectionFunctionAbstract::getShortName — 获取函数短名称
- ReflectionFunctionAbstract::getStartLine — 获取开始行号
- ReflectionFunctionAbstract::getStaticVariables — 获取静态变量
- ReflectionFunctionAbstract::inNamespace — 检查是否处于命名空间
- ReflectionFunctionAbstract::isClosure — 检查是否是匿名函数
- ReflectionFunctionAbstract::isDeprecated — 检查是否已经弃用
- ReflectionFunctionAbstract::isGenerator — 判断函数是否是一个生成器函数
- ReflectionFunctionAbstract::isInternal — 判断函数是否是内置函数
- ReflectionFunctionAbstract::isUserDefined — 检查是否是用户定义
- ReflectionFunctionAbstract::returnsReference — 检查是否返回参考信息
- ReflectionFunctionAbstract::__toString — 字符串化
- ReflectionMethod — ReflectionMethod 类
- ReflectionMethod::__construct — ReflectionMethod 的构造函数
- ReflectionMethod::export — 输出一个回调方法
- ReflectionMethod::getClosure — 返回一个动态建立的方法调用接口,译者注:可以使用这个返回值直接调用非公开方法。
- ReflectionMethod::getDeclaringClass — 获取反射函数调用参数的类表达
- ReflectionMethod::getModifiers — 获取方法的修饰符
- ReflectionMethod::getPrototype — 返回方法原型 (如果存在)
- ReflectionMethod::invoke — Invoke
- ReflectionMethod::invokeArgs — 带参数执行
- ReflectionMethod::isAbstract — 判断方法是否是抽象方法
- ReflectionMethod::isConstructor — 判断方法是否是构造方法
- ReflectionMethod::isDestructor — 判断方法是否是析构方法
- ReflectionMethod::isFinal — 判断方法是否定义 final
- ReflectionMethod::isPrivate — 判断方法是否是私有方法
- ReflectionMethod::isProtected — 判断方法是否是保护方法 (protected)
- ReflectionMethod::isPublic — 判断方法是否是公开方法
- ReflectionMethod::isStatic — 判断方法是否是静态方法
- ReflectionMethod::setAccessible — 设置方法是否访问
- ReflectionMethod::__toString — 返回反射方法对象的字符串表达
- ReflectionObject — ReflectionObject 类
- ReflectionObject::__construct — Constructs a ReflectionObject
- ReflectionObject::export — Export
- ReflectionParameter — ReflectionParameter 类
- ReflectionParameter::allowsNull — Checks if null is allowed
- ReflectionParameter::canBePassedByValue — Returns whether this parameter can be passed by value
- ReflectionParameter::__clone — Clone
- ReflectionParameter::__construct — Construct
- ReflectionParameter::export — Exports
- ReflectionParameter::getClass — Get the type hinted class
- ReflectionParameter::getDeclaringClass — Gets declaring class
- ReflectionParameter::getDeclaringFunction — Gets declaring function
- ReflectionParameter::getDefaultValue — Gets default parameter value
- ReflectionParameter::getDefaultValueConstantName — Returns the default value's constant name if default value is constant or null
- ReflectionParameter::getName — Gets parameter name
- ReflectionParameter::getPosition — Gets parameter position
- ReflectionParameter::isArray — Checks if parameter expects an array
- ReflectionParameter::isCallable — Returns whether parameter MUST be callable
- ReflectionParameter::isDefaultValueAvailable — Checks if a default value is available
- ReflectionParameter::isDefaultValueConstant — Returns whether the default value of this parameter is constant
- ReflectionParameter::isOptional — Checks if optional
- ReflectionParameter::isPassedByReference — Checks if passed by reference
- ReflectionParameter::__toString — To string
- ReflectionProperty — ReflectionProperty 类
- ReflectionProperty::__clone — Clone
- ReflectionProperty::__construct — Construct a ReflectionProperty object
- ReflectionProperty::export — Export
- ReflectionProperty::getDeclaringClass — Gets declaring class
- ReflectionProperty::getDocComment — Gets doc comment
- ReflectionProperty::getModifiers — Gets modifiers
- ReflectionProperty::getName — Gets property name
- ReflectionProperty::getValue — Gets value
- ReflectionProperty::isDefault — Checks if default value
- ReflectionProperty::isPrivate — Checks if property is private
- ReflectionProperty::isProtected — Checks if property is protected
- ReflectionProperty::isPublic — Checks if property is public
- ReflectionProperty::isStatic — Checks if property is static
- ReflectionProperty::setAccessible — Set property accessibility
- ReflectionProperty::setValue — Set property value
- ReflectionProperty::__toString — To string
- Reflector — Reflector 接口
- Reflector::export — Exports
- Reflector::__toString — 转化成字符串
- ReflectionException — ReflectionException 类
php反射机制的更多相关文章
- Java学习之反射机制及应用场景
前言: 最近公司正在进行业务组件化进程,其中的路由实现用到了Java的反射机制,既然用到了就想着好好学习总结一下,其实无论是之前的EventBus 2.x版本还是Retrofit.早期的View注解框 ...
- 第28章 java反射机制
java反射机制 1.类加载机制 1.1.jvm和类 运行Java程序:java 带有main方法的类名 之后java会启动jvm,并加载字节码(字节码就是一个类在内存空间的状态) 当调用java命令 ...
- NPOI操作EXCEL(四)——反射机制批量导出excel文件
前面我们已经实现了反射机制进行excel表格数据的解析,既然有上传就得有下载,我们再来写一个通用的导出方法,利用反射机制实现对系统所有数据列表的筛选结果导出excel功能. 我们来构想一下这样一个画面 ...
- Java反射机制
Java反射机制 一:什么事反射机制 简单地说,就是程序运行时能够通过反射的到类的所有信息,只需要获得类名,方法名,属性名. 二:为什么要用反射: 静态编译:在编译时确定类型,绑定对象,即通过 ...
- java基础知识(十一)java反射机制(上)
java.lang.Class类详解 java Class类详解 一.class类 Class类是java语言定义的特定类的实现,在java中每个类都有一个相应的Class对象,以便java程序运行时 ...
- java基础知识(十一)java反射机制(下)
1.什么是反射机制? java反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法,对于任意一个对象都能够调用他的属性和方法,这种动态获取属性和方法的功能称为java的反射机制. ...
- c#反射机制
一:反射的定义 审查元数据并收集关于它的类型信息的能力.元数据(编译以后的最基本数据单元)就是一大堆的表,当编译程序集或者模块时,编译器会创建一个类定义表,一个字段定义表,和一个方法定义表等. Sys ...
- java反射学习之一反射机制概述
一.反射机制背景概述 1.反射(reflection)是java被视为动态语言的一个关键性质 2.反射机制指的是程序在运行时能获取任何类的内部所有信息 二.反射机制实现功能概述 1.只要给定类的全名, ...
- Java中的反射机制
Java反射机制 反射机制定义 反射机制是Java语言中一个非常重要的特性,它允许程序在运行时进行自我检查,同时也允许其对内部成员进行操作.由于反射机制能够实现在运行时对类进行装载,因此能够增加程序的 ...
- C#反射机制 (转载)
转载:原文出处 http://www.cnblogs.com/binfire/archive/2013/01/17/2864887.html 一:反射的定义 审查元数据并收集关于它的类型信息 ...
随机推荐
- ❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️html,js随笔。❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️
a标签本身的文字居中. a{ display:block; text-align:center; } 设置div1在另一个div2里居中,(写了左边margin 就别写右边了不然ie6有毛病,当然本身 ...
- R语言XML格式数据导入与处理
数据解析 XML是一种可扩展标记语言,它被设计用来传输和存储数据.XML是各种应用程序之间进行数据传输的最常用的工具.它与Access,Oracle和SQL Server等数据库不同,数据库提供了更强 ...
- ArcGIS server 开发实践之【FeatureLayer类】
全是干活,你值得拥有 要素图层类简介:Class:FeatureLayer //调用方式:require(["esri/layers/FeatureLayer"],function ...
- windows Python 3.4.3 安装图文
1.去官网(https://www.python.org/downloads/)下载软件. 2.运行安装程序: 下一步 next. 下一步 next 全部选中,下一步 next. 安装中..来自:ht ...
- 定制Eclipse IDE之界面篇
为什么要定制IDE? 在工作时候,当公司有了自己的框架,给自己开放人员用,甚至是可以卖的时候,我们可以做成一个产品,而这个产品将包括框架本身.文档.工具.教程等等.工具之中最重要的莫过于开发 ...
- web时代变迁及html5与4的区别
HTML5的新结构标签 在之前的HTML页面中,大家基本上都是用了Div+CSS的布局方式.而搜索引擎去抓取页面的内容的时候,它只能猜测 你的某个Div内的内容是文章内容容器,或者是导航模块的容器,或 ...
- SQLServer ForXmlPath应用
SQLServer ForXmlPath应用 一:ForXmlPath介绍 forXmlPath 是SQL中的forXml语法的一部分,本文主要讲Path模式 ---SQL中FOR XML子句的 ...
- IOS开发--微信支付
前言:下面介绍微信支付的开发流程的细节,图文并茂,你可以按照我的随笔流程过一遍代码.包你也学会了微信支付.而且支付也是面试常问的内容. 正文: 1.首先在开始使用微信支付之前,有一些东西是开发者必须要 ...
- iOS运用fabric记录crash日志过程
先前运用友盟记录app闪退,发现有些闪退的记录无法明确定位到详细的位置,决定运用fabric进行闪退的记录:网上也有这方面的记录,有些细节的内容不明确,把今天碰到的坑整理记发不一下: 访问官网地址(进 ...
- 网络热恋之json解析
现在的app开发很少有用到XML解析的了,主流的则是JSON. // // ViewController.m // CX-JSON解析(三方JSONKit-master) #import " ...