Book/reflection-Phpdoc专题
反射
目录
- 简介
- 安装/配置
- 预定义常量
- 范例
- 扩展
- 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::getReflectionConstant — Gets a ReflectionClassConstant for a class's constant
- ReflectionClass::getReflectionConstants — Gets class constants
- 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::isAnonymous — 检查类是否是匿名类
- ReflectionClass::isCloneable — 返回了一个类是否可复制
- ReflectionClass::isFinal — 检查类是否声明为 final
- ReflectionClass::isInstance — 检查类的实例
- ReflectionClass::isInstantiable — 检查类是否可实例化
- ReflectionClass::isInterface — 检查类是否是一个接口(interface)
- ReflectionClass::isInternal — 检查类是否由扩展或核心在内部定义
- ReflectionClass::isIterable — Check whether this class is iterable
- ReflectionClass::isIterateable — 检查是否可迭代(iterateable)
- ReflectionClass::isSubclassOf — 检查是否为一个子类
- ReflectionClass::isTrait — 返回了是否为一个 trait
- ReflectionClass::isUserDefined — 检查是否由用户定义的
- ReflectionClass::newInstance — 从指定的参数创建一个新的类实例
- ReflectionClass::newInstanceArgs — 从给出的参数创建一个新的类实例。
- ReflectionClass::newInstanceWithoutConstructor — 创建一个新的类实例而不调用它的构造函数
- ReflectionClass::setStaticPropertyValue — 设置静态属性的值
- ReflectionClass::__toString — 返回 ReflectionClass 对象字符串的表示形式。
- ReflectionClassConstant — The
ReflectionClassConstant class
- ReflectionClassConstant::__construct — Constructs a ReflectionClassConstant
- ReflectionClassConstant::export — Export
- ReflectionClassConstant::getDeclaringClass — Gets declaring class
- ReflectionClassConstant::getDocComment — Gets doc comments
- ReflectionClassConstant::getModifiers — Gets the class constant modifiers
- ReflectionClassConstant::getName — Get name of the constant
- ReflectionClassConstant::getValue — Gets value
- ReflectionClassConstant::isPrivate — Checks if class constant is private
- ReflectionClassConstant::isProtected — Checks if class constant is protected
- ReflectionClassConstant::isPublic — Checks if class constant is public
- ReflectionClassConstant::__toString — Returns the string representation of the ReflectionClassConstant object
- 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 — 获取类名称
- ReflectionExtension::getConstants — 获取常量
- ReflectionExtension::getDependencies — 获取依赖
- ReflectionExtension::getFunctions — 获取扩展中的函数
- ReflectionExtension::getINIEntries — 获取ini配置
- ReflectionExtension::getName — 获取扩展名称
- ReflectionExtension::getVersion — 获取扩展版本号
- ReflectionExtension::info — 输出扩展信息
- ReflectionExtension::isPersistent — 返回扩展是否持久化载入
- ReflectionExtension::isTemporary — 返回扩展是否是临时载入
- 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::getReturnType — Gets the specified return type of a function
- ReflectionFunctionAbstract::getShortName — 获取函数短名称
- ReflectionFunctionAbstract::getStartLine — 获取开始行号
- ReflectionFunctionAbstract::getStaticVariables — 获取静态变量
- ReflectionFunctionAbstract::hasReturnType — Checks if the function has a specified return type
- ReflectionFunctionAbstract::inNamespace — 检查是否处于命名空间
- ReflectionFunctionAbstract::isClosure — 检查是否是匿名函数
- ReflectionFunctionAbstract::isDeprecated — 检查是否已经弃用
- ReflectionFunctionAbstract::isGenerator — 判断函数是否是一个生成器函数
- ReflectionFunctionAbstract::isInternal — 判断函数是否是内置函数
- ReflectionFunctionAbstract::isUserDefined — 检查是否是用户定义
- ReflectionFunctionAbstract::isVariadic — Checks if the function is variadic
- 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 — 获得类型提示类。
- 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::getType — Gets a parameter's type
- ReflectionParameter::hasType — Checks if parameter has a type
- ReflectionParameter::isArray — Checks if parameter expects an array
- ReflectionParameter::isCallable — Returns whether parameter MUST be callable
- ReflectionParameter::isDefaultValueAvailable — 检查是否有默认值。
- ReflectionParameter::isDefaultValueConstant — Returns whether the default value of this parameter is a constant
- ReflectionParameter::isOptional — Checks if optional
- ReflectionParameter::isPassedByReference — Checks if passed by reference
- ReflectionParameter::isVariadic — Checks if the parameter is variadic
- ReflectionParameter::__toString — To string
- ReflectionProperty —
ReflectionProperty 类
- ReflectionProperty::__clone — Clone
- ReflectionProperty::__construct — Construct a ReflectionProperty object
- ReflectionProperty::export — Export
- ReflectionProperty::getDeclaringClass — Gets declaring class
- ReflectionProperty::getDefaultValue — Returns the default value declared for a property
- ReflectionProperty::getDocComment — Gets the property doc comment
- ReflectionProperty::getModifiers — Gets the property modifiers
- ReflectionProperty::getName — Gets property name
- ReflectionProperty::getType — Gets a property's type
- ReflectionProperty::getValue — Gets value
- ReflectionProperty::hasDefaultValue — Checks if property has a default value declared
- ReflectionProperty::hasType — Checks if property has a type
- ReflectionProperty::isDefault — Checks if property is a default property
- ReflectionProperty::isInitialized — Checks whether a property is initialized
- 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
- ReflectionType — The ReflectionType
class
- ReflectionType::allowsNull — Checks if null is allowed
- ReflectionType::__toString — To string
- ReflectionGenerator —
生成器反射类
- ReflectionGenerator::__construct — Constructs a ReflectionGenerator object
- ReflectionGenerator::getExecutingFile — Gets the file name of the currently executing generator
- ReflectionGenerator::getExecutingGenerator — Gets the executing Generator object
- ReflectionGenerator::getExecutingLine — Gets the currently executing line of the generator
- ReflectionGenerator::getFunction — Gets the function name of the generator
- ReflectionGenerator::getThis — Gets the $this value of the generator
- ReflectionGenerator::getTrace — Gets the trace of the executing generator
- Reflector — Reflector 接口
- Reflector::export — Exports
- Reflector::__toString — 转化成字符串
- ReflectionException — ReflectionException 类
简介
反射(reflection)类。
类摘要
Reflection
class Reflection {
/* 方法 */
public <span
class="modifier">static string <span
class="methodname">export ( <span
class="type">Reflector $reflector [, <span
class="methodparam">bool $return<span
class="initializer"> = false ] )
public <span
class="modifier">static array <span
class="methodname">getModifierNames ( <span
class="methodparam">int $modifiers )
}
Reflection::export
Exports
说明
public <span
class="modifier">static string <span
class="methodname">Reflection::export ( <span
class="methodparam">Reflector
$reflector [, <span
class="type">bool $return =
false ] )
导出一个反射(reflection)。
Warning
本函数还未编写文档,仅有参数列表。
参数
reflector
导出的反射。
return
设为 true 时返回导出结果,设为 false(默认值)则忽略返回。
返回值
如果参数 return 设为 true,导出结果将作为 <span
class="type">string 返回,否则返回 null。
参见
- Reflection::getModifierNames
Reflection::getModifierNames
获取修饰符的名称
说明
public <span
class="modifier">static array <span
class="methodname">Reflection::getModifierNames ( <span
class="methodparam">int $modifiers )
获取修饰符的名称。
参数
modifiers
根据标志位域获取修饰符。
返回值
修饰符名称的一个数组。
范例
示例 #1 Reflection::getModifierNames 例子
<?php
class Testing
{
final public static function foo()
{
return;
}
public function bar()
{
return;
}
}
$foo = new ReflectionMethod('Testing', 'foo');
echo "Modifiers for method foo():\n";
echo $foo->getModifiers() . "\n";
echo implode(' ', Reflection::getModifierNames($foo->getModifiers())) . "\n";
$bar = new ReflectionMethod('Testing', 'bar');
echo "Modifiers for method bar():\n";
echo $bar->getModifiers() . "\n";
echo implode(' ', Reflection::getModifierNames($bar->getModifiers()));
以上例程的输出类似于:
Modifiers for method foo():
261
final public static
Modifiers for method bar():
65792
public
参见
- ReflectionClass::getModifiers
- <span class="methodname">ReflectionClassConstant::getModifiers
- ReflectionMethod::getModifiers
- ReflectionProperty::getModifiers
简介
ReflectionClass 类报告了一个类的有关信息。
类摘要
ReflectionClass
class ReflectionClass <span class="oointerface">implements <span class="interfacename">Reflector {
/* 常量 */
const integer
ReflectionClass::IS_IMPLICIT_ABSTRACT =
16 ;
const integer
ReflectionClass::IS_EXPLICIT_ABSTRACT =
32 ;
const integer
ReflectionClass::IS_FINAL = 64 ;
/* 属性 */
public $name ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">mixed $argument )
public <span
class="modifier">static string <span
class="methodname">export ( <span
class="type">mixed $argument [, <span
class="methodparam">bool $return<span
class="initializer"> = false ] )
public mixed
getConstant ( <span
class="methodparam">string $name )
public array getConstants ( <span class="methodparam">void )
public <span class="type">ReflectionMethod <span class="methodname">getConstructor ( <span class="methodparam">void )
public array getDefaultProperties ( <span class="methodparam">void )
public string getDocComment ( <span class="methodparam">void )
public int <span class="methodname">getEndLine ( <span class="methodparam">void )
public <span class="type">ReflectionExtension <span class="methodname">getExtension ( <span class="methodparam">void )
public string getExtensionName ( <span class="methodparam">void )
public string getFileName ( <span class="methodparam">void )
public array getInterfaceNames ( <span class="methodparam">void )
public array getInterfaces ( <span class="methodparam">void )
public <span
class="type">ReflectionMethod <span
class="methodname">getMethod ( <span
class="type">string $name )
public array
getMethods ([ <span
class="methodparam">int $filter ] )
public int <span class="methodname">getModifiers ( <span class="methodparam">void )
public string getName ( <span class="methodparam">void )
public string getNamespaceName ( <span class="methodparam">void )
public <span class="type">ReflectionClass <span class="methodname">getParentClass ( <span class="methodparam">void )
public array
getProperties ([ <span
class="methodparam">int $filter ] )
public <span
class="type">ReflectionProperty <span
class="methodname">getProperty ( <span
class="type">string $name )
public <span
class="type">ReflectionClassConstant<span
class="type">false <span
class="methodname">getReflectionConstant ( <span
class="methodparam">string $name )
public array getReflectionConstants ( <span class="methodparam">void )
public string getShortName ( <span class="methodparam">void )
public int <span class="methodname">getStartLine ( <span class="methodparam">void )
public array getStaticProperties ( <span class="methodparam">void )
public mixed
getStaticPropertyValue ( <span
class="methodparam">string $name [,
mixed
&$def_value ] )
public array getTraitAliases ( <span class="methodparam">void )
public array getTraitNames ( <span class="methodparam">void )
public array getTraits ( <span class="methodparam">void )
public bool
hasConstant ( <span
class="methodparam">string $name )
public bool
hasMethod ( <span
class="methodparam">string $name )
public bool
hasProperty ( <span
class="methodparam">string $name )
public bool
implementsInterface ( <span
class="methodparam">string $interface
)
public bool inNamespace ( <span class="methodparam">void )
public bool isAbstract ( <span class="methodparam">void )
public bool isAnonymous ( <span class="methodparam">void )
public bool isCloneable ( <span class="methodparam">void )
public bool isFinal ( <span class="methodparam">void )
public bool
isInstance ( <span
class="methodparam">object $object )
public bool isInstantiable ( <span class="methodparam">void )
public bool isInterface ( <span class="methodparam">void )
public bool isInternal ( <span class="methodparam">void )
public bool isIterable ( <span class="methodparam">void )
public bool isIterateable ( <span class="methodparam">void )
public bool
isSubclassOf ( <span
class="methodparam">string $class )
public bool isTrait ( <span class="methodparam">void )
public bool isUserDefined ( <span class="methodparam">void )
public object
newInstance ( <span
class="methodparam">mixed $args [,
mixed $...
] )
public object
newInstanceArgs ([ <span
class="methodparam">array $args ] )
public object newInstanceWithoutConstructor ( <span class="methodparam">void )
public void
setStaticPropertyValue ( <span
class="methodparam">string $name ,
string
$value )
public string __toString ( <span class="methodparam">void )
}
属性
name
类的名称。只读,并在尝试赋值的时候会抛出 <span
class="classname">ReflectionException。
预定义常量
ReflectionClass 修饰符
ReflectionClass::IS_IMPLICIT_ABSTRACT
指示了类是一个抽象类(abstract),
因为它有抽象(abstract)方法。
ReflectionClass::IS_EXPLICIT_ABSTRACT
指示了类是一个抽象类(abstract),
因为它已明确定义。
ReflectionClass::IS_FINAL
指示这是一个 final
类。
ReflectionClass::__construct
初始化 ReflectionClass 类
说明
public <span
class="methodname">ReflectionClass::__construct ( <span
class="methodparam">mixed $argument )
初始化新的 ReflectionClass 对象。
参数
argument
既可以是包含类名的字符串(<span
class="type">string)也可以是对象(<span
class="type">object)。
返回值
返回初始化完成后的 ReflectionClass 实例。
错误/异常
如果要反射的 Class 不存在,抛出异常 <span class="classname">ReflectionException。
范例
示例 #1 ReflectionClass 的基本用法
<?php
Reflection::export(new ReflectionClass('Exception'));
?>
以上例程的输出类似于:
Class [ <internal:Core> class Exception ] {
- Constants [0] {
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [7] {
Property [ <default> protected $message ]
Property [ <default> private $string ]
Property [ <default> protected $code ]
Property [ <default> protected $file ]
Property [ <default> protected $line ]
Property [ <default> private $trace ]
Property [ <default> private $previous ]
}
- Methods [10] {
Method [ <internal:Core> final private method __clone ] {
}
Method [ <internal:Core, ctor> public method __construct ] {
- Parameters [3] {
Parameter #0 [ <optional> $message ]
Parameter #1 [ <optional> $code ]
Parameter #2 [ <optional> $previous ]
}
}
Method [ <internal:Core> final public method getMessage ] {
}
Method [ <internal:Core> final public method getCode ] {
}
Method [ <internal:Core> final public method getFile ] {
}
Method [ <internal:Core> final public method getLine ] {
}
Method [ <internal:Core> final public method getTrace ] {
}
Method [ <internal:Core> final public method getPrevious ] {
}
Method [ <internal:Core> final public method getTraceAsString ] {
}
Method [ <internal:Core> public method __toString ] {
}
}
}
参见
- ReflectionObject::__construct
- Constructors
ReflectionClass::export
导出一个类
说明
public <span
class="modifier">static string <span
class="methodname">ReflectionClass::export ( <span
class="methodparam">mixed $argument
[, bool
$return = false ] )
导出一个反射后的类。
参数
argument
导出的反射。
return
设为 true 时返回导出结果,设为 false(默认值)则忽略返回。
返回值
如果参数 return 设为 true,导出结果将作为 <span
class="type">string 返回,否则返回 null。
范例
示例 #1 ReflectionClass::export 的基本用法
<?php
class Apple {
public $var1;
public $var2 = 'Orange';
public function type() {
return 'Apple';
}
}
ReflectionClass::export('Apple');
?>
以上例程的输出类似于:
Class [ <user> class Apple ] {
@@ php shell code 1-8
- Constants [0] {
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [2] {
Property [ <default> public $var1 ]
Property [ <default> public $var2 ]
}
- Methods [1] {
Method [ <user> public method type ] {
@@ php shell code 5 - 7
}
}
}
参见
- ReflectionClass::getName
ReflectionClass::getConstant
获取定义过的一个常量
说明
public mixed
ReflectionClass::getConstant ( <span
class="methodparam">string $name )
获取定义过的一个常量。
Warning
本函数还未编写文档,仅有参数列表。
参数
name
常量的名称。
返回值
常量的值。
参见
- ReflectionClass::getConstants
ReflectionClass::getConstants
获取一组常量
说明
public array ReflectionClass::getConstants ( <span class="methodparam">void )
获取某个类的全部已定义的常量,不管可见性如何定义。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
常量的<span class="type">数组,常量名是数组的键,常量的值是数组的值。
参见
- ReflectionClass::getConstant
ReflectionClass::getConstructor
获取类的构造函数
说明
public <span class="type">ReflectionMethod <span class="methodname">ReflectionClass::getConstructor ( <span class="methodparam">void )
获取已反射的类的构造函数。
参数
此函数没有参数。
返回值
一个 ReflectionMethod
对象,反射了类的构造函数,或者当类不存在构造函数时返回 null。
范例
示例 #1 <span class="methodname">ReflectionClass::getConstructor 的基本用法
<?php
$class = new ReflectionClass('ReflectionClass');
$constructor = $class->getConstructor();
var_dump($constructor);
?>
以上例程会输出:
object(ReflectionMethod)#2 (2) {
["name"]=>
string(11) "__construct"
["class"]=>
string(15) "ReflectionClass"
}
参见
- ReflectionClass::getName
ReflectionClass::getDefaultProperties
获取默认属性
说明
public array ReflectionClass::getDefaultProperties ( void )
获取类的默认属性(包括了继承的属性)。
Note:
This method only works for static properties when used on internal classes. The default value of a static class property can not be tracked when using this method on user defined classes.
参数
此函数没有参数。
返回值
默认属性的<span
class="type">数组,其键是属性的名称,其值是属性的默认值或者在属性没有默认值时是
null。 这个函数不区分静态和非静态属性,也不考虑可见性修饰符。
范例
示例 #1 <span class="methodname">ReflectionClass::getDefaultProperties 例子
<?php
class Bar {
protected $inheritedProperty = 'inheritedDefault';
}
class Foo extends Bar {
public $property = 'propertyDefault';
private $privateProperty = 'privatePropertyDefault';
public static $staticProperty = 'staticProperty';
public $defaultlessProperty;
}
$reflectionClass = new ReflectionClass('Foo');
var_dump($reflectionClass->getDefaultProperties());
?>
以上例程会输出:
array(5) {
["staticProperty"]=>
string(14) "staticProperty"
["property"]=>
string(15) "propertyDefault"
["privateProperty"]=>
string(22) "privatePropertyDefault"
["defaultlessProperty"]=>
NULL
["inheritedProperty"]=>
string(16) "inheritedDefault"
}
参见
- ReflectionClass::getProperties
- ReflectionClass::getStaticProperties
- ReflectionClass::getProperty
ReflectionClass::getDocComment
获取文档注释
说明
public string ReflectionClass::getDocComment ( <span class="methodparam">void )
从一个类中获取文档注释。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
如果存在则返回文档注释,否则返回 false。
范例
示例 #1 <span class="methodname">ReflectionClass::getDocComment 例子
<?php
/**
* A test class
*
* @param foo bar
* @return baz
*/
class TestClass { }
$rc = new ReflectionClass('TestClass');
var_dump($rc->getDocComment())
?>
以上例程会输出:
string(55) "/**
* A test class
*
* @param foo bar
* @return baz
*/"
参见
- ReflectionClass::getName
ReflectionClass::getEndLine
获取最后一行的行数
说明
public int <span class="methodname">ReflectionClass::getEndLine ( <span class="methodparam">void )
从用户定义的类获取其最后一行的行数。
参数
此函数没有参数。
返回值
返回用户定义的类最后一行的行数,如果未知则返回 false。
范例
示例 #1 ReflectionClass::getEndLine 例子
<?php
// Test Class
class TestClass { }
$rc = new ReflectionClass('TestClass');
echo $rc->getEndLine();
?>
以上例程会输出:
3
参见
- ReflectionClass::getStartLine
ReflectionClass::getExtension
根据已定义的类获取所在扩展的 <span class="classname">ReflectionExtension 对象
说明
public <span class="type">ReflectionExtension <span class="methodname">ReflectionClass::getExtension ( <span class="methodparam">void )
获取已定义类的扩展的 ReflectionExtension 对象。
参数
此函数没有参数。
返回值
类所处的扩展的 ReflectionExtension
对象的表示,如果是用户定义的类则返回 null。
范例
示例 #1 ReflectionClass::getExtension 的基本用法
<?php
$class = new ReflectionClass('ReflectionClass');
$extension = $class->getExtension();
var_dump($extension);
?>
以上例程会输出:
object(ReflectionExtension)#2 (1) {
["name"]=>
string(10) "Reflection"
}
参见
- ReflectionClass::getExtensionName
ReflectionClass::getExtensionName
获取定义的类所在的扩展的名称
说明
public string ReflectionClass::getExtensionName ( void )
获取定义的类所在的扩展的名称。
参数
此函数没有参数。
返回值
获取定义的类所在的扩展的名称,如果是用户定义的类,则返回 false。
范例
示例 #1 <span class="methodname">ReflectionClass::getExtensionName 的基本用法
<?php
$class = new ReflectionClass('ReflectionClass');
$extension = $class->getExtensionName();
var_dump($extension);
?>
以上例程会输出:
string(10) "Reflection"
参见
- ReflectionClass::getExtension
ReflectionClass::getFileName
获取定义类的文件名
说明
public string ReflectionClass::getFileName ( <span class="methodparam">void )
获取类被定义的文件的文件名。
参数
此函数没有参数。
返回值
返回类所定义的文件名。如果这个类是在 PHP 核心或 PHP 扩展中定义的,则返回
false。
参见
- ReflectionClass::getExtensionName
ReflectionClass::getInterfaceNames
获取接口(interface)名称
说明
public array ReflectionClass::getInterfaceNames ( void )
获取接口(interface)名称。
参数
此函数没有参数。
返回值
一个数值数组,接口(interface)的名称是数组的值。
范例
示例 #1 <span class="methodname">ReflectionClass::getInterfaceNames 例子
<?php
interface Foo { }
interface Bar { }
class Baz implements Foo, Bar { }
$rc1 = new ReflectionClass("Baz");
print_r($rc1->getInterfaceNames());
?>
以上例程的输出类似于:
Array
(
[0] => Foo
[1] => Bar
)
参见
- ReflectionClass::getInterfaces
ReflectionClass::getInterfaces
获取接口
说明
public array ReflectionClass::getInterfaces ( <span class="methodparam">void )
获取接口。
参数
此函数没有参数。
返回值
接口的关联<span class="type">数组,数组键是接口(interface)的名称,数组的值是 ReflectionClass 对象。
范例
示例 #1 <span class="methodname">ReflectionClass::getInterfaces 例子
<?php
interface Foo { }
interface Bar { }
class Baz implements Foo, Bar { }
$rc1 = new ReflectionClass("Baz");
print_r($rc1->getInterfaces());
?>
以上例程的输出类似于:
Array
(
[Foo] => ReflectionClass Object
(
[name] => Foo
)
[Bar] => ReflectionClass Object
(
[name] => Bar
)
)
参见
- ReflectionClass::getInterfaceNames
ReflectionClass::getMethod
获取一个类方法的 ReflectionMethod。
说明
public <span
class="type">ReflectionMethod <span
class="methodname">ReflectionClass::getMethod ( <span
class="methodparam">string $name )
获取一个类方法的 ReflectionMethod。
参数
name
要反射的方法名称。
返回值
一个 ReflectionMethod。
错误/异常
如果方法不存在则会抛出 <span class="classname">ReflectionException 异常。
范例
示例 #1 ReflectionClass::getMethod 的基本用法
<?php
$class = new ReflectionClass('ReflectionClass');
$method = $class->getMethod('getMethod');
var_dump($method);
?>
以上例程会输出:
object(ReflectionMethod)#2 (2) {
["name"]=>
string(9) "getMethod"
["class"]=>
string(15) "ReflectionClass"
}
参见
- ReflectionClass::getMethods
ReflectionClass::getMethods
获取方法的数组
说明
public array
ReflectionClass::getMethods ([ <span
class="methodparam">int $filter ] )
获取类的方法的一个数组。
参数
filter
过滤结果为仅包含某些属性的方法。默认不过滤。
ReflectionMethod::IS_STATIC、 ReflectionMethod::IS_PUBLIC、
ReflectionMethod::IS_PROTECTED、
ReflectionMethod::IS_PRIVATE、
ReflectionMethod::IS_ABSTRACT、 ReflectionMethod::IS_FINAL
的按位或(OR),就会返回任意满足条件的属性。
Note: 请注意:其他位操作,例如 ~ 无法按预期运行。这个例子也就是说,无法获取所有的非静态方法。
返回值
包含每个方法 ReflectionMethod 对象的<span class="type">数组。
范例
示例 #1 ReflectionClass::getMethods 的基本用法
<?php
class Apple {
public function firstMethod() { }
final protected function secondMethod() { }
private static function thirdMethod() { }
}
$class = new ReflectionClass('Apple');
$methods = $class->getMethods();
var_dump($methods);
?>
以上例程会输出:
array(3) {
[0]=>
&object(ReflectionMethod)#2 (2) {
["name"]=>
string(11) "firstMethod"
["class"]=>
string(5) "Apple"
}
[1]=>
&object(ReflectionMethod)#3 (2) {
["name"]=>
string(12) "secondMethod"
["class"]=>
string(5) "Apple"
}
[2]=>
&object(ReflectionMethod)#4 (2) {
["name"]=>
string(11) "thirdMethod"
["class"]=>
string(5) "Apple"
}
}
示例 #2 从 <span class="methodname">ReflectionClass::getMethods 中过滤结果
<?php
class Apple {
public function firstMethod() { }
final protected function secondMethod() { }
private static function thirdMethod() { }
}
$class = new ReflectionClass('Apple');
$methods = $class->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_FINAL);
var_dump($methods);
?>
以上例程会输出:
array(2) {
[0]=>
&object(ReflectionMethod)#2 (2) {
["name"]=>
string(12) "secondMethod"
["class"]=>
string(5) "Apple"
}
[1]=>
&object(ReflectionMethod)#3 (2) {
["name"]=>
string(11) "thirdMethod"
["class"]=>
string(5) "Apple"
}
}
参见
- ReflectionClass::getMethod
- get_class_methods
ReflectionClass::getModifiers
获取类的修饰符
说明
public int <span class="methodname">ReflectionClass::getModifiers ( <span class="methodparam">void )
返回这个类访问修饰符的位字段。
参数
此函数没有参数。
返回值
返回 修饰符常量 的位掩码。
参见
- ReflectionClass::getProperties
- Reflection::getModifierNames
ReflectionClass::getName
获取类名
说明
public string ReflectionClass::getName ( <span class="methodparam">void )
获取类的名称。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The class name.
范例
示例 #1 ReflectionClass::getName 例子
<?php
namespace A\B;
class Foo { }
$function = new \ReflectionClass('stdClass');
var_dump($function->inNamespace());
var_dump($function->getName());
var_dump($function->getNamespaceName());
var_dump($function->getShortName());
$function = new \ReflectionClass('A\\B\\Foo');
var_dump($function->inNamespace());
var_dump($function->getName());
var_dump($function->getNamespaceName());
var_dump($function->getShortName());
?>
以上例程会输出:
bool(false)
string(8) "stdClass"
string(0) ""
string(8) "stdClass"
bool(true)
string(7) "A\B\Foo"
string(3) "A\B"
string(3) "Foo"
参见
- ReflectionClass::getNamespaceName
ReflectionClass::getNamespaceName
获取命名空间的名称
说明
public string ReflectionClass::getNamespaceName ( void )
获取命名空间(namespace)的名称。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
命名空间的名称。
范例
示例 #1 <span class="methodname">ReflectionClass::getNamespaceName 例子
<?php
namespace A\B;
class Foo { }
$class = new \ReflectionClass('stdClass');
var_dump($class->inNamespace());
var_dump($class->getName());
var_dump($class->getNamespaceName());
var_dump($class->getShortName());
$class = new \ReflectionClass('A\\B\\Foo');
var_dump($class->inNamespace());
var_dump($class->getName());
var_dump($class->getNamespaceName());
var_dump($class->getShortName());
?>
以上例程会输出:
bool(false)
string(8) "stdClass"
string(0) ""
string(8) "stdClass"
bool(true)
string(7) "A\B\Foo"
string(3) "A\B"
string(3) "Foo"
参见
- ReflectionClass::getParentClass
- namespaces
ReflectionClass::getParentClass
获取父类
说明
public <span class="type">ReflectionClass <span class="methodname">ReflectionClass::getParentClass ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
一个 ReflectionClass。
参见
- ReflectionClass::__construct
ReflectionClass::getProperties
获取一组属性
说明
public array
ReflectionClass::getProperties ([ <span
class="methodparam">int $filter ] )
获取反射过的属性。
参数
filter
可选的过滤器,过滤为所需类型的属性。它使用
ReflectionProperty 常量
来配置,默认获取所有类型的属性。
返回值
ReflectionProperty 对象的数组。
范例
示例 #1 ReflectionClass::getProperties 过滤例子
这个例子延时了可选 filter 参数的用法,例子里实际上忽略了私有属性。
<?php
class Foo {
public $foo = 1;
protected $bar = 2;
private $baz = 3;
}
$foo = new Foo();
$reflect = new ReflectionClass($foo);
$props = $reflect->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);
foreach ($props as $prop) {
print $prop->getName() . "\n";
}
var_dump($props);
?>
以上例程的输出类似于:
foo
bar
array(2) {
[0]=>
object(ReflectionProperty)#3 (2) {
["name"]=>
string(3) "foo"
["class"]=>
string(3) "Foo"
}
[1]=>
object(ReflectionProperty)#4 (2) {
["name"]=>
string(3) "bar"
["class"]=>
string(3) "Foo"
}
}
参见
- ReflectionClass::getProperty
- ReflectionProperty
- ReflectionProperty 修饰符常量
ReflectionClass::getProperty
获取类的一个属性的 ReflectionProperty
说明
public <span
class="type">ReflectionProperty <span
class="methodname">ReflectionClass::getProperty ( <span
class="methodparam">string $name )
获取类的一个属性的 ReflectionProperty。
参数
name
属性名。
返回值
一个 ReflectionProperty。
范例
示例 #1 ReflectionClass::getProperty 的基本用法
<?php
$class = new ReflectionClass('ReflectionClass');
$property = $class->getProperty('name');
var_dump($property);
?>
以上例程会输出:
object(ReflectionProperty)#2 (2) {
["name"]=>
string(4) "name"
["class"]=>
string(15) "ReflectionClass"
}
参见
- ReflectionClass::getProperties
ReflectionClass::getReflectionConstant
Gets a ReflectionClassConstant for a class's constant
说明
public <span
class="type">ReflectionClassConstant<span
class="type">false <span
class="methodname">ReflectionClass::getReflectionConstant ( <span
class="methodparam">string $name )
Gets a ReflectionClassConstant for a class's property.
参数
name
The class constant name.
返回值
A ReflectionClassConstant,
或者在失败时返回 false.
参见
- <span class="methodname">ReflectionClass::getReflectionConstants
- ReflectionClassConstant
ReflectionClass::getReflectionConstants
Gets class constants
说明
public array ReflectionClass::getReflectionConstants ( void )
Retrieves reflected constants.
参数
此函数没有参数。
返回值
An array of ReflectionClassConstant objects.
范例
示例 #1 Basic <span class="function">ReflectionClass::getReflectionConstants example
<?php
class Foo {
public const FOO = 1;
protected const BAR = 2;
private const BAZ = 3;
}
$foo = new Foo();
$reflect = new ReflectionClass($foo);
$consts = $reflect->getReflectionConstants();
foreach ($consts as $const) {
print $const->getName() . "\n";
}
var_dump($consts);
?>
以上例程的输出类似于:
FOO
BAR
BAZ
array(3) {
[0]=>
object(ReflectionClassConstant)#3 (2) {
["name"]=>
string(3) "FOO"
["class"]=>
string(3) "Foo"
}
[1]=>
object(ReflectionClassConstant)#4 (2) {
["name"]=>
string(3) "BAR"
["class"]=>
string(3) "Foo"
}
[2]=>
object(ReflectionClassConstant)#5 (2) {
["name"]=>
string(3) "BAZ"
["class"]=>
string(3) "Foo"
}
}
参见
- <span class="methodname">ReflectionClass::getReflectionConstant
- ReflectionClassConstant
ReflectionClass::getShortName
获取短名
说明
public string ReflectionClass::getShortName ( <span class="methodparam">void )
获取类的短名,就是不含命名空间(namespace)的那一部分。
参数
此函数没有参数。
返回值
类的短名。
范例
示例 #1 ReflectionClass::getShortName 例子
<?php
namespace A\B;
class Foo { }
$function = new \ReflectionClass('stdClass');
var_dump($function->inNamespace());
var_dump($function->getName());
var_dump($function->getNamespaceName());
var_dump($function->getShortName());
$function = new \ReflectionClass('A\\B\\Foo');
var_dump($function->inNamespace());
var_dump($function->getName());
var_dump($function->getNamespaceName());
var_dump($function->getShortName());
?>
以上例程会输出:
bool(false)
string(8) "stdClass"
string(0) ""
string(8) "stdClass"
bool(true)
string(7) "A\B\Foo"
string(3) "A\B"
string(3) "Foo"
参见
- ReflectionClass::getName
ReflectionClass::getStartLine
获取起始行号
说明
public int <span class="methodname">ReflectionClass::getStartLine ( <span class="methodparam">void )
获取起始的行号。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
起始的行号,类型是 integer 的。
参见
- ReflectionClass::getEndLine
ReflectionClass::getStaticProperties
获取静态(static)属性
说明
public array ReflectionClass::getStaticProperties ( void )
获取静态(static)属性。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
静态(static)的属性,类型是 array。
参见
- <span class="methodname">ReflectionClass::getStaticPropertyValue
- <span class="methodname">ReflectionClass::setStaticPropertyValue
ReflectionClass::getStaticPropertyValue
获取静态(static)属性的值
说明
public mixed
ReflectionClass::getStaticPropertyValue
( string
$name [, <span
class="type">mixed &$def_value ] )
获取这个类里静态(static)属性的值。
参数
name
静态属性的名称,来返回它的值。
def_value
假如类没有定义 name 的 static 属性,将返回一个默认值。
如果属性不存在,并且省略了此参数,将会抛出 <span
class="classname">ReflectionException 。
返回值
静态属性的值。
范例
示例 #1 <span class="methodname">ReflectionClass::getStaticPropertyValue 的基本用法
<?php
class Apple {
public static $color = 'Red';
}
$class = new ReflectionClass('Apple');
var_dump($class->getStaticPropertyValue('color'));
?>
以上例程会输出:
string(3) "Red"
参见
- ReflectionClass::getStaticProperties
- <span class="methodname">ReflectionClass::setStaticPropertyValue
ReflectionClass::getTraitAliases
返回 trait 别名的一个数组
说明
public array ReflectionClass::getTraitAliases ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
返回了一个数组,新的方法名位于键中,原始名称(格式是
"TraitName::original")位于数组的值中。 出现一个错误的情况下返回
null。
ReflectionClass::getTraitNames
返回这个类所使用 traits 的名称的数组
说明
public array ReflectionClass::getTraitNames ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
返回的数组的值包含了 trait 的名称。 出现错误的情况下返回 null。
ReflectionClass::getTraits
返回这个类所使用的 traits 数组
说明
public array ReflectionClass::getTraits ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
返回了一个数组,键是 trait 的名称,值是 trait 实例的 <span
class="classname">ReflectionClass。 出现错误的情况下返回
null。
ReflectionClass::hasConstant
检查常量是否已经定义
说明
public bool
ReflectionClass::hasConstant ( <span
class="methodparam">string $name )
检查类中是否已经定义了指定的常量。
参数
name
要被检查的常量名称。
返回值
如果已定义返回 true,否则返回 false。
范例
示例 #1 ReflectionClass::hasConstant 例子
<?php
class Foo {
const c1 = 1;
}
$class = new ReflectionClass("Foo");
var_dump($class->hasConstant("c1"));
var_dump($class->hasConstant("c2"));
?>
以上例程的输出类似于:
bool(true)
bool(false)
参见
- ReflectionClass::hasMethod
- ReflectionClass::hasProperty
ReflectionClass::hasMethod
检查方法是否已定义
说明
public bool
ReflectionClass::hasMethod ( <span
class="methodparam">string $name )
检查一个类中指定的方法是否已定义。
参数
name
要检查的方法的名称。
返回值
如果有这个方法返回 true,否则返回 false。
范例
示例 #1 ReflectionClass::hasMethod 例子
<?php
Class C {
public function publicFoo() {
return true;
}
protected function protectedFoo() {
return true;
}
private function privateFoo() {
return true;
}
static function staticFoo() {
return true;
}
}
$rc = new ReflectionClass("C");
var_dump($rc->hasMethod('publicFoo'));
var_dump($rc->hasMethod('protectedFoo'));
var_dump($rc->hasMethod('privateFoo'));
var_dump($rc->hasMethod('staticFoo'));
// C should not have method bar
var_dump($rc->hasMethod('bar'));
// Method names are case insensitive
var_dump($rc->hasMethod('PUBLICfOO'));
?>
以上例程会输出:
bool(true)
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)
参见
- ReflectionClass::hasConstant
- ReflectionClass::hasProperty
ReflectionClass::hasProperty
检查属性是否已定义
说明
public bool
ReflectionClass::hasProperty ( <span
class="methodparam">string $name )
检查指定的属性是否已定义。
参数
name
待检查的属性的名称。
返回值
如果有这个属性返回 true,否则返回 false。
范例
示例 #1 ReflectionClass::hasProperty 例子
<?php
class Foo {
public $p1;
protected $p2;
private $p3;
}
$obj = new ReflectionObject(new Foo());
var_dump($obj->hasProperty("p1"));
var_dump($obj->hasProperty("p2"));
var_dump($obj->hasProperty("p3"));
var_dump($obj->hasProperty("p4"));
?>
以上例程的输出类似于:
bool(true)
bool(true)
bool(true)
bool(false)
参见
- ReflectionClass::hasConstant
- ReflectionClass::hasMethod
ReflectionClass::implementsInterface
接口的实现
说明
public bool
ReflectionClass::implementsInterface (
string
$interface )
检查它是否实现了一个接口(interface)。
参数
interface
接口(interface)的名称。
返回值
成功时返回 true, 或者在失败时返回 false。
参见
- ReflectionClass::isInterface
- ReflectionClass::isSubclassOf
- interface_exists
- Object Interfaces
ReflectionClass::inNamespace
检查是否位于命名空间中
说明
public bool ReflectionClass::inNamespace ( <span class="methodparam">void )
检查这个类是否定义于一个命名空间中里。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 ReflectionClass::inNamespace 例子
<?php
namespace A\B;
class Foo { }
$function = new \ReflectionClass('stdClass');
var_dump($function->inNamespace());
var_dump($function->getName());
var_dump($function->getNamespaceName());
var_dump($function->getShortName());
$function = new \ReflectionClass('A\\B\\Foo');
var_dump($function->inNamespace());
var_dump($function->getName());
var_dump($function->getNamespaceName());
var_dump($function->getShortName());
?>
以上例程会输出:
bool(false)
string(8) "stdClass"
string(0) ""
string(8) "stdClass"
bool(true)
string(7) "A\B\Foo"
string(3) "A\B"
string(3) "Foo"
参见
- ReflectionClass::getNamespaceName
- PHP Namespaces
ReflectionClass::isAbstract
检查类是否是抽象类(abstract)
说明
public bool ReflectionClass::isAbstract ( <span class="methodparam">void )
检查这个类是否是抽象类(abstract)。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 ReflectionClass::isAbstract 例子
<?php
class TestClass { }
abstract class TestAbstractClass { }
$testClass = new ReflectionClass('TestClass');
$abstractClass = new ReflectionClass('TestAbstractClass');
var_dump($testClass->isAbstract());
var_dump($abstractClass->isAbstract());
?>
以上例程会输出:
bool(false)
bool(true)
参见
- ReflectionClass::isInterface
- 类的抽象
ReflectionClass::isAnonymous
检查类是否是匿名类
说明
public bool ReflectionClass::isAnonymous ( <span class="methodparam">void )
检查类是否是匿名类。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 ReflectionClass::isAnonymous example
<?php
class TestClass {}
$anonClass = new class {};
$normalClass = new ReflectionClass('TestClass');
$anonClass = new ReflectionClass($anonClass);
var_dump($normalClass->isAnonymous());
var_dump($anonClass->isAnonymous());
?>
以上例程会输出:
bool(false)
bool(true)
参见
- ReflectionClass::isFinal
ReflectionClass::isCloneable
返回了一个类是否可复制
说明
public bool ReflectionClass::isCloneable ( <span class="methodparam">void )
返回了这个类是否可复制。
参数
此函数没有参数。
返回值
如果这个类可以复制返回 true,否则返回 false。
范例
示例 #1 ReflectionClass::isCloneable 的基本用法
<?php
class NotCloneable {
public $var1;
private function __clone() {
}
}
class Cloneable {
public $var1;
}
$notCloneable = new ReflectionClass('NotCloneable');
$cloneable = new ReflectionClass('Cloneable');
var_dump($notCloneable->isCloneable());
var_dump($cloneable->isCloneable());
?>
以上例程会输出:
bool(false)
bool(true)
ReflectionClass::isFinal
检查类是否声明为 final
说明
public bool ReflectionClass::isFinal ( <span class="methodparam">void )
检查类是否声明为 final。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 ReflectionClass::isFinal 例子
<?php
class TestClass { }
final class TestFinalClass { }
$normalClass = new ReflectionClass('TestClass');
$finalClass = new ReflectionClass('TestFinalClass');
var_dump($normalClass->isFinal());
var_dump($finalClass->isFinal());
?>
以上例程会输出:
bool(false)
bool(true)
参见
- ReflectionClass::isAbstract
- Final 关键字
ReflectionClass::isInstance
检查类的实例
说明
public bool
ReflectionClass::isInstance ( <span
class="methodparam">object $object )
检查对象是否为一个类的实例。
参数
object
待比较的对象。
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 ReflectionClass::isInstance 相关例子
<?php
// Example usage
$class = new ReflectionClass('Foo');
if ($class->isInstance($arg)) {
echo "Yes";
}
// Equivalent to
if ($arg instanceof Foo) {
echo "Yes";
}
// Equivalent to
if (is_a($arg, 'Foo')) {
echo "Yes";
}
?>
以上例程的输出类似于:
Yes
Yes
Yes
参见
- ReflectionClass::isInterface
- 类型运算符(instanceof)
- 对象接口
- is_a
ReflectionClass::isInstantiable
检查类是否可实例化
说明
public bool ReflectionClass::isInstantiable ( <span class="methodparam">void )
检查这个类是否可实例化。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 <span class="methodname">ReflectionClass::isInstantiable 例子
<?php
class C { }
interface iface {
function f1();
}
class ifaceImpl implements iface {
function f1() {}
}
abstract class abstractClass {
function f1() { }
abstract function f2();
}
class D extends abstractClass {
function f2() { }
}
class privateConstructor {
private function __construct() { }
}
$classes = array(
"C",
"iface",
"ifaceImpl",
"abstractClass",
"D",
"privateConstructor",
);
foreach($classes as $class ) {
$reflectionClass = new ReflectionClass($class);
echo "Is $class instantiable? ";
var_dump($reflectionClass->IsInstantiable());
}
?>
以上例程会输出:
Is C instantiable? bool(true)
Is iface instantiable? bool(false)
Is ifaceImpl instantiable? bool(true)
Is abstractClass instantiable? bool(false)
Is D instantiable? bool(true)
Is privateConstructor instantiable? bool(false)
参见
- ReflectionClass::isInstance
ReflectionClass::isInterface
检查类是否是一个接口(interface)
说明
public bool ReflectionClass::isInterface ( <span class="methodparam">void )
检查类是否是一个接口(interface)。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 ReflectionClass::isInterface 基本用法
<?php
interface SomeInterface {
public function interfaceMethod();
}
$class = new ReflectionClass('SomeInterface');
var_dump($class->isInterface());
?>
以上例程会输出:
bool(true)
参见
- ReflectionClass::isInstance
ReflectionClass::isInternal
检查类是否由扩展或核心在内部定义
说明
public bool ReflectionClass::isInternal ( <span class="methodparam">void )
检查类是否由扩展或核心在内部定义,与用户定义相反。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 ReflectionClass::isInternal 的基本用法
<?php
$internalclass = new ReflectionClass('ReflectionClass');
class Apple {}
$userclass = new ReflectionClass('Apple');
var_dump($internalclass->isInternal());
var_dump($userclass->isInternal());
?>
以上例程会输出:
bool(true)
bool(false)
参见
- ReflectionClass::isUserDefined
ReflectionClass::isIterable
Check whether this class is iterable
说明
public bool ReflectionClass::isIterable ( <span class="methodparam">void )
Check whether this class is iterable (i.e. can be used inside foreach).
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 Basic <span class="methodname">ReflectionClass::isIterable Usage
<?php
class IteratorClass implements Iterator {
public function __construct() { }
public function key() { }
public function current() { }
function next() { }
function valid() { }
function rewind() { }
}
class DerivedClass extends IteratorClass { }
class NonIterator { }
function dump_iterable($class) {
$reflection = new ReflectionClass($class);
var_dump($reflection->isIterable());
}
$classes = array("ArrayObject", "IteratorClass", "DerivedClass", "NonIterator");
foreach ($classes as $class) {
echo "Is $class iterable? ";
dump_iterable($class);
}
?>
以上例程会输出:
Is ArrayObject iterable? bool(true)
Is IteratorClass iterable? bool(true)
Is DerivedClass iterable? bool(true)
Is NonIterator iterable? bool(false)
参见
- ReflectionClass::__construct
ReflectionClass::isIterateable
检查是否可迭代(iterateable)
说明
public bool ReflectionClass::isIterateable ( <span class="methodparam">void )
检查一个类是否可迭代(iterateable)。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
范例
示例 #1 <span class="methodname">ReflectionClass::isIterateable 例子
<?php
class IteratorClass implements Iterator {
public function __construct() { }
public function key() { }
public function current() { }
function next() { }
function valid() { }
function rewind() { }
}
class DerivedClass extends IteratorClass { }
class NonIterator { }
function dump_iterateable($class) {
$reflection = new ReflectionClass($class);
var_dump($reflection->isIterateable());
}
$classes = array("ArrayObject", "IteratorClass", "DerivedClass", "NonIterator");
foreach ($classes as $class) {
echo "Is $class iterateable? ";
dump_iterateable($class);
}
?>
以上例程会输出:
Is ArrayObject iterateable? bool(true)
Is IteratorClass iterateable? bool(true)
Is DerivedClass iterateable? bool(true)
Is NonIterator iterateable? bool(false)
参见
- ReflectionClass::__construct
ReflectionClass::isSubclassOf
检查是否为一个子类
说明
public bool
ReflectionClass::isSubclassOf ( <span
class="methodparam">string $class )
检查一个类是否为指定类的子类,或者实现了指定的接口。
参数
class
被检查的类名。
返回值
成功时返回 true, 或者在失败时返回 false。
参见
- ReflectionClass::isInterface
- ReflectionClass::implementsInterface
- is_subclass_of
- get_parent_class
ReflectionClass::isTrait
返回了是否为一个 trait
说明
public bool ReflectionClass::isTrait ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
如果是 trait 返回 true,否则返回 false。
在出现错误的情况下,将会返回 null。
ReflectionClass::isUserDefined
检查是否由用户定义的
说明
public bool ReflectionClass::isUserDefined ( <span class="methodparam">void )
检查一个类是否由用户定义,和内置相对。
参数
此函数没有参数。
返回值
成功时返回 true, 或者在失败时返回 false。
参见
- ReflectionClass::isInternal
ReflectionClass::newInstance
从指定的参数创建一个新的类实例
说明
public object
ReflectionClass::newInstance ( <span
class="methodparam">mixed $args [,
mixed $...
] )
创建类的新的实例。给出的参数将会传递到类的构造函数。
参数
args
接受可变数目的参数,用于传递到类的构造函数,和 <span
class="function">call_user_func 很相似。
返回值
错误/异常
如果类的构造函数不是 public 的将会导致一个 <span class="classname">ReflectionException。
当 args 指定了一个或多个参数,而类不具有构造函数时,将导致一个 <span
class="classname">ReflectionException。
参见
- ReflectionClass::newInstanceArgs
- <span class="methodname">ReflectionClass::newInstanceWithoutConstructor
ReflectionClass::newInstanceArgs
从给出的参数创建一个新的类实例。
说明
public object
ReflectionClass::newInstanceArgs ([
array $args
] )
创建一个类的新实例,给出的参数将传递到类的构造函数。
参数
args
这个参数以 array 形式传递到类的构造函数。
返回值
返回类的新实例。
范例
示例 #1 <span class="methodname">ReflectionClass::newInstanceArgs 的基本用法
<?php
$class = new ReflectionClass('ReflectionFunction');
$instance = $class->newInstanceArgs(array('substr'));
var_dump($instance);
?>
以上例程会输出:
object(ReflectionFunction)#2 (1) {
["name"]=>
string(6) "substr"
}
错误/异常
如果类的构造函数不是 public 的将导致产生一个 <span class="classname">ReflectionException。
当 args 指定了一个或多个参数,而类不具有构造函数时,将导致一个 <span
class="classname">ReflectionException。
参见
- ReflectionClass::newInstance
- <span class="methodname">ReflectionClass::newInstanceWithoutConstructor
ReflectionClass::newInstanceWithoutConstructor
创建一个新的类实例而不调用它的构造函数
说明
public object <span class="methodname">ReflectionClass::newInstanceWithoutConstructor ( void )
创建一个新的类的实例而不调用它的构造函数。
参数
返回值
更新日志
| 版本 | 说明 |
|---|---|
| 5.6.0 | All internal classes can now be instantiated except for those declared final. |
错误/异常
如果这个类是一个不能不调用构造函数来实例化的内置类,将导致一个 <span class="classname">ReflectionException。在 PHP 5.6.0 及更高版本中,此异常仅限于 final 的内置类。
参见
- ReflectionClass::newInstance
- ReflectionClass::newInstanceArgs
ReflectionClass::setStaticPropertyValue
设置静态属性的值
说明
public void
ReflectionClass::setStaticPropertyValue
( string
$name , <span
class="type">string $value )
设置静态属性的值。
Warning
本函数还未编写文档,仅有参数列表。
参数
name
属性的名称。
value
属性的值。
返回值
没有返回值。
参见
- <span class="methodname">ReflectionClass::getStaticPropertyValue
ReflectionClass::__toString
返回 ReflectionClass 对象字符串的表示形式。
说明
public string ReflectionClass::__toString ( <span class="methodparam">void )
返回 ReflectionClass 对象字符串的表示形式。
参数
此函数没有参数。
返回值
ReflectionClass 实例的一个字符串表示形式。
范例
示例 #1 ReflectionClass::__toString 例子
<?php
$reflectionClass = new ReflectionClass('Exception');
echo $reflectionClass->__toString();
?>
以上例程会输出:
Class [ <internal:Core> class Exception ] {
- Constants [0] {
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [7] {
Property [ <default> protected $message ]
Property [ <default> private $string ]
Property [ <default> protected $code ]
Property [ <default> protected $file ]
Property [ <default> protected $line ]
Property [ <default> private $trace ]
Property [ <default> private $previous ]
}
- Methods [10] {
Method [ <internal:Core> final private method __clone ] {
}
Method [ <internal:Core, ctor> public method __construct ] {
- Parameters [3] {
Parameter #0 [ <optional> $message ]
Parameter #1 [ <optional> $code ]
Parameter #2 [ <optional> $previous ]
}
}
Method [ <internal:Core> final public method getMessage ] {
}
Method [ <internal:Core> final public method getCode ] {
}
Method [ <internal:Core> final public method getFile ] {
}
Method [ <internal:Core> final public method getLine ] {
}
Method [ <internal:Core> final public method getTrace ] {
}
Method [ <internal:Core> final public method getPrevious ] {
}
Method [ <internal:Core> final public method getTraceAsString ] {
}
Method [ <internal:Core> public method __toString ] {
}
}
}
参见
- ReflectionClass::export
- __toString()
简介
The ReflectionClassConstant class reports information about a class constant.
类摘要
ReflectionClassConstant
class ReflectionClassConstant <span class="oointerface">implements <span class="interfacename">Reflector {
/* 属性 */
public $name ;
public $class ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">mixed $class ,
string
$name )
public <span
class="modifier">static string <span
class="methodname">export ( <span
class="type">mixed $class , <span
class="methodparam">string $name [,
bool
$return ] )
public <span class="type">ReflectionClass <span class="methodname">getDeclaringClass ( <span class="methodparam">void )
public string getDocComment ( <span class="methodparam">void )
public int <span class="methodname">getModifiers ( <span class="methodparam">void )
public string getName ( <span class="methodparam">void )
public mixed getValue ( <span class="methodparam">void )
public bool isPrivate ( <span class="methodparam">void )
public bool isProtected ( <span class="methodparam">void )
public bool isPublic ( <span class="methodparam">void )
public string __toString ( <span class="methodparam">void )
}
属性
name
Name of the class constant. Read-only, throws <span
class="classname">ReflectionException in attempt to write.
class
Name of the class where the class constant is defined. Read-only, throws
ReflectionException in attempt to write.
ReflectionClassConstant::__construct
Constructs a ReflectionClassConstant
说明
public <span
class="methodname">ReflectionClassConstant::__construct ( <span
class="methodparam">mixed $class ,
string
$name )
Constructs a new ReflectionClassConstant object.
参数
class
Either a string containing the name of the
class to reflect, or an object.
name
The name of the class constant.
返回值
Returns constructed <span class="classname">ReflectionClassConstant instance.
错误/异常
Throws an Exception in case the given class constant does not exist.
参见
ReflectionClassConstant::export
Export
Warning
本函数已自 PHP 7.4.0 起废弃。强烈建议不要使用本函数。
说明
public <span
class="modifier">static string <span
class="methodname">ReflectionClassConstant::export ( <span
class="methodparam">mixed $class ,
string
$name [, <span
class="type">bool $return ] )
Exports a reflection.
Warning
本函数还未编写文档,仅有参数列表。
参数
class
导出的反射。
name
The class constant name.
return
设为 true 时返回导出结果,设为 false(默认值)则忽略返回。
返回值
参见
- <span class="methodname">ReflectionClassConstant::__toString
ReflectionClassConstant::getDeclaringClass
Gets declaring class
说明
public <span class="type">ReflectionClass <span class="methodname">ReflectionClassConstant::getDeclaringClass ( void )
Gets the declaring class.
参数
此函数没有参数。
返回值
A ReflectionClass object.
ReflectionClassConstant::getDocComment
Gets doc comments
说明
public string ReflectionClassConstant::getDocComment ( void )
Gets doc comments from a class constant.
参数
此函数没有参数。
返回值
The doc comment if it exists, otherwise false
ReflectionClassConstant::getModifiers
Gets the class constant modifiers
说明
public int <span class="methodname">ReflectionClassConstant::getModifiers ( <span class="methodparam">void )
Returns a bitfield of the access modifiers for this class constant.
参数
此函数没有参数。
返回值
A numeric representation of the modifiers. The actual meanings of these modifiers are described in the predefined constants.
参见
- Reflection::getModifierNames
ReflectionClassConstant::getName
Get name of the constant
说明
public string ReflectionClassConstant::getName ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Returns the constant's name.
ReflectionClassConstant::getValue
Gets value
说明
public mixed ReflectionClassConstant::getValue ( void )
Gets the class constant's value.
参数
此函数没有参数。
返回值
The value of the class constant.
ReflectionClassConstant::isPrivate
Checks if class constant is private
说明
public bool ReflectionClassConstant::isPrivate ( void )
Checks if the class constant is private.
参数
此函数没有参数。
返回值
true if the class constant is private, otherwise false
参见
- ReflectionClassConstant::isPublic
- ReflectionClassConstant::isProtected
ReflectionClassConstant::isProtected
Checks if class constant is protected
说明
public bool ReflectionClassConstant::isProtected ( void )
Checks if the class constant is protected.
参数
此函数没有参数。
返回值
true if the class constant is protected, otherwise false
参见
- ReflectionClassConstant::isPublic
- ReflectionClassConstant::isPrivate
ReflectionClassConstant::isPublic
Checks if class constant is public
说明
public bool ReflectionClassConstant::isPublic ( void )
Checks if the class constant is public.
参数
此函数没有参数。
返回值
true if the class constant is public, otherwise false
参见
- ReflectionClassConstant::isPrivate
- ReflectionClassConstant::isProtected
ReflectionClassConstant::__toString
Returns the string representation of the ReflectionClassConstant object
说明
public string ReflectionClassConstant::__toString ( void )
Returns the string representation of the ReflectionClassConstant object.
参数
此函数没有参数。
返回值
A string representation of this <span class="classname">ReflectionClassConstant instance.
参见
- ReflectionClassConstant::export
- __toString()
简介
类摘要
ReflectionZendExtension
class ReflectionZendExtension <span class="oointerface">implements <span class="interfacename">Reflector {
/* 属性 */
public $name ;
/* 方法 */
final <span class="modifier">private void <span class="methodname">__clone ( <span class="methodparam">void )
public <span
class="methodname">__construct ( <span
class="methodparam">string $name )
public <span
class="modifier">static string <span
class="methodname">export ( <span
class="type">string $name [, <span
class="methodparam">bool $return ] )
public string getAuthor ( <span class="methodparam">void )
public string getCopyright ( <span class="methodparam">void )
public string getName ( <span class="methodparam">void )
public string getURL ( <span class="methodparam">void )
public string getVersion ( <span class="methodparam">void )
public string __toString ( <span class="methodparam">void )
}
属性
name
扩展的名称。只读,并在尝试赋值的时候抛出 <span
class="classname">ReflectionException。
ReflectionZendExtension::__clone
Clone handler
说明
final <span class="modifier">private void <span class="methodname">ReflectionZendExtension::__clone ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
ReflectionZendExtension::__construct
Constructor
说明
public <span
class="methodname">ReflectionZendExtension::__construct ( <span
class="methodparam">string $name )
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
ReflectionZendExtension::export
Export
Warning
本函数已自 PHP 7.4.0 起废弃。强烈建议不要使用本函数。
说明
public <span
class="modifier">static string <span
class="methodname">ReflectionZendExtension::export ( <span
class="methodparam">string $name [,
bool
$return ] )
Warning
本函数还未编写文档,仅有参数列表。
参数
name
return
返回值
参见
- <span class="methodname">ReflectionClassConstant::__toString
ReflectionZendExtension::getAuthor
Gets author
说明
public string ReflectionZendExtension::getAuthor ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
ReflectionZendExtension::getCopyright
Gets copyright
说明
public string ReflectionZendExtension::getCopyright ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
ReflectionZendExtension::getName
Gets name
说明
public string ReflectionZendExtension::getName ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
ReflectionZendExtension::getURL
Gets URL
说明
public string ReflectionZendExtension::getURL ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
ReflectionZendExtension::getVersion
Gets version
说明
public string ReflectionZendExtension::getVersion ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
ReflectionZendExtension::__toString
To string handler
说明
public string ReflectionZendExtension::__toString ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
简介
ReflectionExtension 报告了一个扩展(extension)的有关信息。
类摘要
ReflectionExtension
class ReflectionExtension <span class="oointerface">implements <span class="interfacename">Reflector {
/* 属性 */
public $name ;
/* 方法 */
final <span class="modifier">private void <span class="methodname">__clone ( <span class="methodparam">void )
public <span
class="methodname">__construct ( <span
class="methodparam">string $name )
public <span
class="modifier">static string <span
class="methodname">export ( <span
class="type">string $name [, <span
class="methodparam">string $return<span
class="initializer"> = false ] )
public array getClasses ( <span class="methodparam">void )
public array getClassNames ( <span class="methodparam">void )
public array getConstants ( <span class="methodparam">void )
public array getDependencies ( <span class="methodparam">void )
public array getFunctions ( <span class="methodparam">void )
public array getINIEntries ( <span class="methodparam">void )
public string getName ( <span class="methodparam">void )
public string getVersion ( <span class="methodparam">void )
public void info ( <span class="methodparam">void )
public void isPersistent ( <span class="methodparam">void )
public void isTemporary ( <span class="methodparam">void )
public string __toString ( <span class="methodparam">void )
}
属性
name
扩展的名称,和 <span
class="methodname">ReflectionExtension::getName
方法所返回的一样。
ReflectionExtension::__clone
Clones
说明
final <span class="modifier">private void <span class="methodname">ReflectionExtension::__clone ( <span class="methodparam">void )
clone方法阻止实例克隆。反射类实例不允许被克隆。
参数
此函数没有参数。
返回值
没有返回值,如果被调用将产生fatal错误。
参见
- ReflectionExtension::__construct
- Object cloning
ReflectionExtension::__construct
Constructs a ReflectionExtension
说明
public <span
class="methodname">ReflectionExtension::__construct ( <span
class="methodparam">string $name )
Construct a ReflectionExtension <span class="type">object.
参数
name
扩展的名称。
返回值
A ReflectionExtension <span class="type">object.
范例
示例 #1 ReflectionExtension example
<?php
$ext = new ReflectionExtension('Reflection');
printf('Extension: %s (version: %s)', $ext->getName(), $ext->getVersion());
?>
以上例程的输出类似于:
Extension: Reflection (version: $Revision: 338648 $)
参见
- ReflectionExtension::info
- Constructors
ReflectionExtension::export
Export
说明
public <span
class="modifier">static string <span
class="methodname">ReflectionExtension::export ( <span
class="methodparam">string $name [,
string
$return = false ] )
导出可以被反射的扩展。输出格式同CLI argument --re [extension].
参数
name
导出的反射。
return
设为 true 时返回导出结果,设为 false(默认值)则忽略返回。
返回值
如果参数 return 设为 true,导出结果将作为 <span
class="type">string 返回,否则返回 null。
参见
- ReflectionExtension::info
ReflectionExtension::getClasses
Gets classes
说明
public array ReflectionExtension::getClasses ( <span class="methodparam">void )
从扩展中获取类列表。
参数
此函数没有参数。
返回值
返回一个<span class="classname">ReflectionClass对象数组,包括扩展中所有类。如果扩展中没有类声明,将返回空数组。
范例
示例 #1 <span class="methodname">ReflectionExtension::getClasses example
<?php
$ext = new ReflectionExtension('XMLWriter');
var_dump($ext->getClasses());
?>
以上例程的输出类似于:
array(1) {
["XMLWriter"]=>
&object(ReflectionClass)#2 (1) {
["name"]=>
string(9) "XMLWriter"
}
}
参见
- ReflectionExtension::getClassNames
ReflectionExtension::getClassNames
获取类名称
说明
public array ReflectionExtension::getClassNames ( void )
获取扩展中的类名称列表。
参数
此函数没有参数。
返回值
返回类名称数组。如果扩展中没有类声明,将返回空数组。
范例
示例 #1 <span class="methodname">ReflectionExtension::getClassNames example
<?php
$ext = new ReflectionExtension('XMLWriter');
var_dump($ext->getClassNames());
?>
以上例程的输出类似于:
array(1) {
[0]=>
string(9) "XMLWriter"
}
参见
- ReflectionExtension::getClasses
- ReflectionExtension::getName
ReflectionExtension::getConstants
获取常量
说明
public array ReflectionExtension::getConstants ( void )
获取扩展中定义的常量。
参数
此函数没有参数。
返回值
返回一个以常量名称为索引的数组。
范例
示例 #1 <span class="methodname">ReflectionExtension::getConstants example
<?php
$ext = new ReflectionExtension('DOM');
print_r($ext->getConstants());
?>
以上例程的输出类似于:
Array
(
[XML_ELEMENT_NODE] => 1
[XML_ATTRIBUTE_NODE] => 2
[XML_TEXT_NODE] => 3
[XML_CDATA_SECTION_NODE] => 4
[XML_ENTITY_REF_NODE] => 5
[XML_ENTITY_NODE] => 6
[XML_PI_NODE] => 7
[XML_COMMENT_NODE] => 8
[XML_DOCUMENT_NODE] => 9
[XML_DOCUMENT_TYPE_NODE] => 10
[XML_DOCUMENT_FRAG_NODE] => 11
[XML_NOTATION_NODE] => 12
[XML_HTML_DOCUMENT_NODE] => 13
[XML_DTD_NODE] => 14
[XML_ELEMENT_DECL_NODE] => 15
[XML_ATTRIBUTE_DECL_NODE] => 16
[XML_ENTITY_DECL_NODE] => 17
[XML_NAMESPACE_DECL_NODE] => 18
[XML_LOCAL_NAMESPACE] => 18
[XML_ATTRIBUTE_CDATA] => 1
[XML_ATTRIBUTE_ID] => 2
[XML_ATTRIBUTE_IDREF] => 3
[XML_ATTRIBUTE_IDREFS] => 4
[XML_ATTRIBUTE_ENTITY] => 6
[XML_ATTRIBUTE_NMTOKEN] => 7
[XML_ATTRIBUTE_NMTOKENS] => 8
[XML_ATTRIBUTE_ENUMERATION] => 9
[XML_ATTRIBUTE_NOTATION] => 10
[DOM_PHP_ERR] => 0
[DOM_INDEX_SIZE_ERR] => 1
[DOMSTRING_SIZE_ERR] => 2
[DOM_HIERARCHY_REQUEST_ERR] => 3
[DOM_WRONG_DOCUMENT_ERR] => 4
[DOM_INVALID_CHARACTER_ERR] => 5
[DOM_NO_DATA_ALLOWED_ERR] => 6
[DOM_NO_MODIFICATION_ALLOWED_ERR] => 7
[DOM_NOT_FOUND_ERR] => 8
[DOM_NOT_SUPPORTED_ERR] => 9
[DOM_INUSE_ATTRIBUTE_ERR] => 10
[DOM_INVALID_STATE_ERR] => 11
[DOM_SYNTAX_ERR] => 12
[DOM_INVALID_MODIFICATION_ERR] => 13
[DOM_NAMESPACE_ERR] => 14
[DOM_INVALID_ACCESS_ERR] => 15
[DOM_VALIDATION_ERR] => 16
)
参见
- ReflectionExtension::getINIEntries
ReflectionExtension::getDependencies
获取依赖
说明
public array ReflectionExtension::getDependencies ( void )
获取依赖,包括必需的、冲突的、可选的。 Gets dependencies, by listing both required and conflicting dependencies.
参数
此函数没有参数。
返回值
返回一个以依赖的扩展名称为索引的数组,每一项的取值为 Required、Optional 或者 Conflicts。
范例
示例 #1 <span class="methodname">ReflectionExtension::getDependencies example
<?php
$dom = new ReflectionExtension('dom');
print_r($dom->getDependencies());
?>
以上例程的输出类似于:
Array
(
[libxml] => Required
[domxml] => Conflicts
)
参见
- ReflectionClass::getVersion
ReflectionExtension::getFunctions
获取扩展中的函数
说明
public array ReflectionExtension::getFunctions ( void )
获取扩展中定义的函数。
参数
此函数没有参数。
返回值
返回一个<span class="classname">ReflectionFunction对象数组,数组索引为函数名。如果扩展中没有定义函数,将返回空数组。
范例
示例 #1 <span class="methodname">ReflectionExtension::getFunctions example
<?php
$dom = new ReflectionExtension('SimpleXML');
print_r($dom->getFunctions());
?>
以上例程的输出类似于:
Array
(
[simplexml_load_file] => ReflectionFunction Object
(
[name] => simplexml_load_file
)
[simplexml_load_string] => ReflectionFunction Object
(
[name] => simplexml_load_string
)
[simplexml_import_dom] => ReflectionFunction Object
(
[name] => simplexml_import_dom
)
)
参见
- ReflectionExtension::getClasses
- get_extension_funcs
ReflectionExtension::getINIEntries
获取ini配置
说明
public array ReflectionExtension::getINIEntries ( void )
获取扩展在ini配置文件中的配置。
参数
此函数没有参数。
返回值
返回一个数组,数组索引是配置名称,值是配置值。
范例
示例 #1 <span class="methodname">ReflectionExtension::getINIEntries example
<?php
$ext = new ReflectionExtension('mysql');
print_r($ext->getINIEntries());
?>
以上例程的输出类似于:
Array
(
[mysql.allow_persistent] => 1
[mysql.max_persistent] => -1
[mysql.max_links] => -1
[mysql.default_host] =>
[mysql.default_user] =>
[mysql.default_password] =>
[mysql.default_port] =>
[mysql.default_socket] =>
[mysql.connect_timeout] => 60
[mysql.trace_mode] =>
[mysql.allow_local_infile] => 1
[mysql.cache_size] => 2000
)
参见
- ini_get_all
- ReflectionExtension::getConstants
ReflectionExtension::getName
获取扩展名称
说明
public string ReflectionExtension::getName ( <span class="methodparam">void )
获取扩展名称。
参数
此函数没有参数。
返回值
扩展名称。
范例
示例 #1 ReflectionExtension::getName example
<?php
$ext = new ReflectionExtension('mysqli');
var_dump($ext->getName());
?>
以上例程的输出类似于:
string(6) "mysqli"
参见
- ReflectionExtension::getClassNames
ReflectionExtension::getVersion
获取扩展版本号
说明
public string ReflectionExtension::getVersion ( <span class="methodparam">void )
获取扩展的版本号。
参数
此函数没有参数。
返回值
扩展的版本号。
范例
示例 #1 <span class="methodname">ReflectionExtension::getVersion example
<?php
$ext = new ReflectionExtension('mysqli');
var_dump($ext->getVersion());
?>
以上例程的输出类似于:
string(3) "0.1"
参见
- ReflectionExtension::info
ReflectionExtension::info
输出扩展信息
说明
public void ReflectionExtension::info ( <span class="methodparam">void )
输出“phpinfo”信息中的扩展信息。
参数
此函数没有参数。
返回值
扩展信息。
范例
示例 #1 ReflectionExtension::info example
<?php
$ext = new ReflectionExtension('mysqli');
$ext->info();
?>
以上例程的输出类似于:
mysqli
MysqlI Support => enabled
Client API library version => mysqlnd 5.0.5-dev - 081106 - $Revision: 339009 $
Active Persistent Links => 0
Inactive Persistent Links => 0
Active Links => 0
Persistent cache => enabled
put_hits => 0
put_misses => 0
get_hits => 0
get_misses => 0
size => 2000
free_items => 2000
references => 2
Directive => Local Value => Master Value
mysqli.max_links => Unlimited => Unlimited
mysqli.max_persistent => Unlimited => Unlimited
mysqli.allow_persistent => On => On
mysqli.default_host => no value => no value
mysqli.default_user => no value => no value
mysqli.default_pw => no value => no value
mysqli.default_port => 3306 => 3306
mysqli.default_socket => no value => no value
mysqli.reconnect => Off => Off
mysqli.allow_local_infile => On => On
mysqli.cache_size => 2000 => 2000
参见
- ReflectionExtension::getName
- phpinfo
ReflectionExtension::isPersistent
返回扩展是否持久化载入
说明
public void ReflectionExtension::isPersistent ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
扩展在extension配置中被载入返回true
,否则返回 false。
参见
- ReflectionExtension::isTemporary
ReflectionExtension::isTemporary
返回扩展是否是临时载入
说明
public void ReflectionExtension::isTemporary ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
如果扩展被dl载入则返回true
,否则返回 false 。
参见
- ReflectionExtension::isPersistent
ReflectionExtension::__toString
To string
说明
public string ReflectionExtension::__toString ( void )
以string形式返回扩展的反射信息。同 <span
class="methodname">ReflectionExtension::exportreturn参数设置为true。
参数
此函数没有参数。
返回值
返回扩展的反射信息,同 <span class="methodname">ReflectionExtension::export。
参见
- ReflectionExtension::__construct
- ReflectionExtension::export
- __toString()
简介
ReflectionFunction 类报告了一个函数的有关信息。
类摘要
ReflectionFunction
class ReflectionFunction <span class="ooclass"> extends ReflectionFunctionAbstract <span class="oointerface">implements <span class="interfacename">Reflector {
/* 常量 */
const integer
ReflectionFunction::IS_DEPRECATED =
262144 ;
/* 属性 */
public $name ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">mixed $name )
public <span
class="modifier">static string <span
class="methodname">export ( <span
class="type">string $name [, <span
class="methodparam">string $return ]
)
public Closure getClosure ( <span class="methodparam">void )
public mixed
invoke ( <span
class="type">mixed $args )
public mixed
invokeArgs ( <span
class="methodparam">array $args )
public bool isDisabled ( <span class="methodparam">void )
public string __toString ( <span class="methodparam">void )
/* 继承的方法 */
final <span class="modifier">private void <span class="methodname">ReflectionFunctionAbstract::__clone ( <span class="methodparam">void )
public <span class="type">ReflectionClass <span class="methodname">ReflectionFunctionAbstract::getClosureScopeClass ( void )
public object <span class="methodname">ReflectionFunctionAbstract::getClosureThis ( void )
public string <span class="methodname">ReflectionFunctionAbstract::getDocComment ( void )
public int <span class="methodname">ReflectionFunctionAbstract::getEndLine ( <span class="methodparam">void )
public <span class="type">ReflectionExtension <span class="methodname">ReflectionFunctionAbstract::getExtension ( void )
public string <span class="methodname">ReflectionFunctionAbstract::getExtensionName ( void )
public string ReflectionFunctionAbstract::getFileName ( void )
public string ReflectionFunctionAbstract::getName ( void )
public string <span class="methodname">ReflectionFunctionAbstract::getNamespaceName ( void )
public int <span class="methodname">ReflectionFunctionAbstract::getNumberOfParameters ( void )
public int <span class="methodname">ReflectionFunctionAbstract::getNumberOfRequiredParameters ( void )
public array <span class="methodname">ReflectionFunctionAbstract::getParameters ( void )
public <span class="type">ReflectionType <span class="methodname">ReflectionFunctionAbstract::getReturnType ( void )
public string ReflectionFunctionAbstract::getShortName ( void )
public int <span class="methodname">ReflectionFunctionAbstract::getStartLine ( void )
public array <span class="methodname">ReflectionFunctionAbstract::getStaticVariables ( void )
public bool <span class="methodname">ReflectionFunctionAbstract::hasReturnType ( void )
public bool ReflectionFunctionAbstract::inNamespace ( void )
public bool ReflectionFunctionAbstract::isClosure ( void )
public bool ReflectionFunctionAbstract::isDeprecated ( void )
public bool ReflectionFunctionAbstract::isGenerator ( void )
public bool ReflectionFunctionAbstract::isInternal ( void )
public bool <span class="methodname">ReflectionFunctionAbstract::isUserDefined ( void )
public bool ReflectionFunctionAbstract::isVariadic ( void )
public bool <span class="methodname">ReflectionFunctionAbstract::returnsReference ( void )
abstract <span class="modifier">public void <span class="methodname">ReflectionFunctionAbstract::__toString ( void )
}
属性
name
函数的名称。只读,并在尝试赋值的时候会抛出 <span
class="classname">ReflectionException。
预定义常量
ReflectionFunction 修饰符
ReflectionFunction::IS_DEPRECATED
指示了不建议使用的函数。
ReflectionFunction::__construct
Constructs a ReflectionFunction object
说明
public <span
class="methodname">ReflectionFunction::__construct ( <span
class="methodparam">mixed $name )
Constructs a ReflectionFunction object.
参数
name
The name of the function to reflect or a
closure.
返回值
没有返回值。
错误/异常
A ReflectionException if the name
parameter does not contain a valid function.
范例
示例 #1 <span class="methodname">ReflectionFunction::__construct example
<?php
/**
* A simple counter
*
* @return int
*/
function counter1()
{
static $c = 0;
return ++$c;
}
/**
* Another simple counter
*
* @return int
*/
$counter2 = function()
{
static $d = 0;
return ++$d;
};
function dumpReflectionFunction($func)
{
// Print out basic information
printf(
"\n\n===> The %s function '%s'\n".
" declared in %s\n".
" lines %d to %d\n",
$func->isInternal() ? 'internal' : 'user-defined',
$func->getName(),
$func->getFileName(),
$func->getStartLine(),
$func->getEndline()
);
// Print documentation comment
printf("---> Documentation:\n %s\n", var_export($func->getDocComment(), 1));
// Print static variables if existant
if ($statics = $func->getStaticVariables())
{
printf("---> Static variables: %s\n", var_export($statics, 1));
}
}
// Create an instance of the ReflectionFunction class
dumpReflectionFunction(new ReflectionFunction('counter1'));
dumpReflectionFunction(new ReflectionFunction($counter2));
?>
以上例程的输出类似于:
===> The user-defined function 'counter1'
declared in Z:\reflectcounter.php
lines 7 to 11
---> Documentation:
'/**
* A simple counter
*
* @return int
*/'
---> Static variables: array (
'c' => 0,
)
===> The user-defined function '{closure}'
declared in Z:\reflectcounter.php
lines 18 to 23
---> Documentation:
'/**
* Another simple counter
*
* @return int
*/'
---> Static variables: array (
'd' => 0,
)
参见
- ReflectionMethod::__construct
- Constructors
ReflectionFunction::export
Exports function
Warning
本函数已自 PHP 7.4.0 起废弃。强烈建议不要使用本函数。
说明
public <span
class="modifier">static string <span
class="methodname">ReflectionFunction::export ( <span
class="methodparam">string $name [,
string
$return ] )
Exports a Reflected function.
参数
name
导出的反射。
return
设为 true 时返回导出结果,设为 false(默认值)则忽略返回。
返回值
如果参数 return 设为 true,导出结果将作为 <span
class="type">string 返回,否则返回 null。
参见
- ReflectionFunction::invoke
- ReflectionFunction::__toString
ReflectionFunction::getClosure
Returns a dynamically created closure for the function
说明
public Closure ReflectionFunction::getClosure ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Returns Closure. Returns null in
case of an error.
ReflectionFunction::invoke
Invokes function
说明
public mixed
ReflectionFunction::invoke ( <span
class="methodparam">mixed $args )
Invokes a reflected function.
参数
args
The passed in argument list. It accepts a variable number of arguments
which are passed to the function much like <span
class="function">call_user_func is.
返回值
Returns the result of the invoked function call.
范例
示例 #1 ReflectionFunction::invoke example
<?php
function title($title, $name)
{
return sprintf("%s. %s\r\n", $title, $name);
}
$function = new ReflectionFunction('title');
echo $function->invoke('Dr', 'Phil');
?>
以上例程会输出:
Dr. Phil
注释
Note:
如果函数有参数需为引用,那么它们必须以引用方式传入。
参见
- ReflectionFunction::export
- __invoke()
- call_user_func
ReflectionFunction::invokeArgs
Invokes function args
说明
public mixed
ReflectionFunction::invokeArgs ( <span
class="methodparam">array $args )
Invokes the function and pass its arguments as array.
参数
args
The passed arguments to the function as an array, much like <span
class="function">call_user_func_array works.
返回值
Returns the result of the invoked function
范例
示例 #1 <span class="methodname">ReflectionFunction::invokeArgs example
<?php
function title($title, $name)
{
return sprintf("%s. %s\r\n", $title, $name);
}
$function = new ReflectionFunction('title');
echo $function->invokeArgs(array('Dr', 'Phil'));
?>
以上例程会输出:
Dr. Phil
示例 #2 <span class="methodname">ReflectionFunction::invokeArgs with references example
<?php
function get_false_conditions(array $conditions, array &$false_conditions)
{
foreach ($conditions as $condition) {
if (!$condition) {
$false_conditions[] = $condition;
}
}
}
$function_ref = new ReflectionFunction('get_false_conditions');
$conditions = array(true, false, -1, 0, 1);
$false_conditions = array();
$function_ref->invokeArgs(array($conditions, &$false_conditions));
var_dump($false_conditions);
?>
以上例程会输出:
array(2) {
[0]=>
bool(false)
[1]=>
int(0)
}
注释
Note:
如果函数有参数需为引用,那么它们必须以引用方式传入。
参见
- ReflectionFunction::invoke
- <span class="methodname">ReflectionFunctionAbstract::getNumberOfParameters
- __invoke()
- call_user_func_array
ReflectionFunction::isDisabled
Checks if function is disabled
说明
public bool ReflectionFunction::isDisabled ( <span class="methodparam">void )
Checks if the function is disabled, via the disable_functions directive.
参数
此函数没有参数。
返回值
true if it's disable, otherwise false
参见
- <span class="methodname">ReflectionFunctionAbstract::isUserDefined
- disable_functions directive
ReflectionFunction::__toString
To string
说明
public string ReflectionFunction::__toString ( <span class="methodparam">void )
To string.
参数
此函数没有参数。
返回值
Returns ReflectionFunction::export-like output for the function.
范例
示例 #1 <span class="methodname">ReflectionFunction::__toString example
<?php
function title($title, $name)
{
return sprintf("%s. %s\r\n", $title, $name);
}
echo new ReflectionFunction('title');
?>
以上例程的输出类似于:
Function [ <user> function title ] {
@@ Command line code 1 - 1
- Parameters [2] {
Parameter #0 [ <required> $title ]
Parameter #1 [ <required> $name ]
}
}
参见
- ReflectionFunction::export
- ReflectionClass::clone
- __toString()
简介
ReflectionFunction 的父类,详情请阅读它的描述。
类摘要
ReflectionFunctionAbstract
class ReflectionFunctionAbstract implements <span class="interfacename">Reflector {
/* 属性 */
public $name ;
/* 方法 */
final <span class="modifier">private void <span class="methodname">__clone ( <span class="methodparam">void )
public <span class="type">ReflectionClass <span class="methodname">getClosureScopeClass ( <span class="methodparam">void )
public object getClosureThis ( <span class="methodparam">void )
public string getDocComment ( <span class="methodparam">void )
public int <span class="methodname">getEndLine ( <span class="methodparam">void )
public <span class="type">ReflectionExtension <span class="methodname">getExtension ( <span class="methodparam">void )
public string getExtensionName ( <span class="methodparam">void )
public string getFileName ( <span class="methodparam">void )
public string getName ( <span class="methodparam">void )
public string getNamespaceName ( <span class="methodparam">void )
public int <span class="methodname">getNumberOfParameters ( <span class="methodparam">void )
public int <span class="methodname">getNumberOfRequiredParameters ( <span class="methodparam">void )
public array getParameters ( <span class="methodparam">void )
public <span class="type">ReflectionType <span class="methodname">getReturnType ( <span class="methodparam">void )
public string getShortName ( <span class="methodparam">void )
public int <span class="methodname">getStartLine ( <span class="methodparam">void )
public array getStaticVariables ( <span class="methodparam">void )
public bool hasReturnType ( <span class="methodparam">void )
public bool inNamespace ( <span class="methodparam">void )
public bool isClosure ( <span class="methodparam">void )
public bool isDeprecated ( <span class="methodparam">void )
public bool isGenerator ( <span class="methodparam">void )
public bool isInternal ( <span class="methodparam">void )
public bool isUserDefined ( <span class="methodparam">void )
public bool isVariadic ( <span class="methodparam">void )
public bool returnsReference ( <span class="methodparam">void )
abstract <span class="modifier">public void <span class="methodname">__toString ( <span class="methodparam">void )
}
属性
name
函数的名称。只读,尝试赋值的时候将会抛出 <span
class="classname">ReflectionException。
ReflectionFunctionAbstract::__clone
复制函数
说明
final <span class="modifier">private void <span class="methodname">ReflectionFunctionAbstract::__clone ( <span class="methodparam">void )
复制函数
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
参见
ReflectionFunctionAbstract::getClosureScopeClass
Returns the scope associated to the closure
说明
public <span class="type">ReflectionClass <span class="methodname">ReflectionFunctionAbstract::getClosureScopeClass ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Returns the class on success or null on failure.
ReflectionFunctionAbstract::getClosureThis
返回本身的匿名函数
说明
public object <span class="methodname">ReflectionFunctionAbstract::getClosureThis ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
返回 $this 指向,产生错误返回 null
ReflectionFunctionAbstract::getDocComment
获取注释内容
说明
public string <span class="methodname">ReflectionFunctionAbstract::getDocComment ( void )
获取函数的注释文本
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
如果存在注释文本返回其内容,否则返回 false
参见
- <span class="methodname">ReflectionFunctionAbstract::getStartLine
ReflectionFunctionAbstract::getEndLine
获取结束行号
说明
public int <span class="methodname">ReflectionFunctionAbstract::getEndLine ( <span class="methodparam">void )
获取结束行号
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
获取用户定义函数的结束行号,如果未知返回 false
参见
- <span class="methodname">ReflectionFunctionAbstract::getStartLine
ReflectionFunctionAbstract::getExtension
获取扩展信息
说明
public <span class="type">ReflectionExtension <span class="methodname">ReflectionFunctionAbstract::getExtension ( void )
获取函数的扩展信息
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
返回 ReflectionExtension 对象,包含扩展信息
参见
- <span class="methodname">ReflectionFunctionAbstract::getExtensionName
ReflectionFunctionAbstract::getExtensionName
获取扩展名称
说明
public string <span class="methodname">ReflectionFunctionAbstract::getExtensionName ( void )
获取扩展名称
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
返回扩展名称
参见
- <span class="methodname">ReflectionFunctionAbstract::getExtension
ReflectionFunctionAbstract::getFileName
获取文件名称
说明
public string ReflectionFunctionAbstract::getFileName ( void )
获取函数定义的文件名称
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The file name.
参见
- <span class="methodname">ReflectionFunctionAbstract::getNamespaceName
ReflectionFunctionAbstract::getName
获取函数名称
说明
public string ReflectionFunctionAbstract::getName ( void )
获取函数名称
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
返回函数名称
参见
- <span class="methodname">ReflectionFunctionAbstract::getExtensionName
- <span class="methodname">ReflectionFunctionAbstract::isUserDefined
ReflectionFunctionAbstract::getNamespaceName
获取命名空间
说明
public string <span class="methodname">ReflectionFunctionAbstract::getNamespaceName ( void )
获取类定义所属的命名空间
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
返回命名空间
参见
- <span class="methodname">ReflectionFunctionAbstract::getFileName
- namespaces
ReflectionFunctionAbstract::getNumberOfParameters
获取参数数目
说明
public int <span class="methodname">ReflectionFunctionAbstract::getNumberOfParameters ( void )
获取函数定义的参数数目,包括可选参数
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
参数的个数
参见
- <span class="methodname">ReflectionFunctionAbstract::getNumberOfRequiredParameters
- func_num_args
ReflectionFunctionAbstract::getNumberOfRequiredParameters
获取必须输入参数个数
说明
public int <span class="methodname">ReflectionFunctionAbstract::getNumberOfRequiredParameters ( void )
获取函数定义中,必须输入的参数个数
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
必须输入的参数个数
参见
- <span class="methodname">ReflectionFunctionAbstract::getNumberOfParameters
ReflectionFunctionAbstract::getParameters
获取参数
说明
public array <span class="methodname">ReflectionFunctionAbstract::getParameters ( void )
通过 ReflectionParameter 数组返回参数列表
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
一组 ReflectionParameter 对象表示每一参数
参见
- <span class="methodname">ReflectionFunctionAbstract::getNumberOfParameters
- func_get_args
ReflectionFunctionAbstract::getReturnType
Gets the specified return type of a function
说明
public <span class="type">ReflectionType <span class="methodname">ReflectionFunctionAbstract::getReturnType ( void )
Gets the specified return type of a reflected function.
参数
此函数没有参数。
返回值
Returns a ReflectionType object if a
return type is specified, null otherwise.
范例
示例 #1 <span class="methodname">ReflectionFunctionAbstract::getReturnType example
<?php
function to_int($param) : int {
return (int) $param;
}
$reflection1 = new ReflectionFunction('to_int');
echo $reflection1->getReturnType();
以上例程会输出:
int
示例 #2 Usage on built-in functions
<?php
$reflection2 = new ReflectionFunction('array_merge');
var_dump($reflection2->getReturnType());
以上例程会输出:
null
This is because many internal functions do not have types specified for their parameters or return values. It is therefore best to avoid using this method on built-in functions.
参见
- <span class="methodname">ReflectionFunctionAbstract::hasReturnType
- ReflectionType::__toString
ReflectionFunctionAbstract::getShortName
获取函数短名称
说明
public string ReflectionFunctionAbstract::getShortName ( void )
获取函数的段名称 (没有命名空间定义)
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
函数短名称
参见
- <span class="methodname">ReflectionFunctionAbstract::getNamespaceName
- namespaces
ReflectionFunctionAbstract::getStartLine
获取开始行号
说明
public int <span class="methodname">ReflectionFunctionAbstract::getStartLine ( void )
获取函数定义的开始行号
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
开始行号
参见
- <span class="methodname">ReflectionFunctionAbstract::getEndLine
ReflectionFunctionAbstract::getStaticVariables
获取静态变量
说明
public array <span class="methodname">ReflectionFunctionAbstract::getStaticVariables ( void )
获取静态变量
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
返回一个静态变量的 array
参见
- <span class="methodname">ReflectionFunctionAbstract::getParameters
ReflectionFunctionAbstract::hasReturnType
Checks if the function has a specified return type
说明
public bool <span class="methodname">ReflectionFunctionAbstract::hasReturnType ( void )
Checks whether the reflected function has a return type specified.
参数
此函数没有参数。
返回值
Returns true if the function is a specified return type, otherwise
false.
范例
示例 #1 <span class="methodname">ReflectionFunctionAbstract::hasReturnType example
<?php
function to_int($param) : int {
return (int) $param;
}
$reflection1 = new ReflectionFunction('to_int');
var_dump($reflection1->hasReturnType());
以上例程会输出:
bool(true)
示例 #2 Usage on built-in functions
<?php
$reflection2 = new ReflectionFunction('array_merge');
var_dump($reflection2->hasReturnType());
以上例程会输出:
bool(false)
This is because many internal functions do not have types specified for their parameters or return values. It is therefore best to avoid using this method on built-in functions.
参见
- <span class="methodname">ReflectionFunctionAbstract::getReturnType
ReflectionFunctionAbstract::inNamespace
检查是否处于命名空间
说明
public bool ReflectionFunctionAbstract::inNamespace ( void )
检查函数是否在命名空间内定义
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
在命名空间内返回 true,否则返回 false
参见
- <span class="methodname">ReflectionFunctionAbstract::getNamespaceName
- namespaces
ReflectionFunctionAbstract::isClosure
检查是否是匿名函数
说明
public bool ReflectionFunctionAbstract::isClosure ( void )
检查是否是匿名函数
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
匿名函数返回 true,否则返回 false
参见
- ReflectionFunctionAbstract::
ReflectionFunctionAbstract::isDeprecated
检查是否已经弃用
说明
public bool ReflectionFunctionAbstract::isDeprecated ( void )
检查函数是否已经被弃用
参数
此函数没有参数。
返回值
弃用返回 true,否则返回 false
范例
示例 #1 <span class="methodname">ReflectionFunctionAbstract::isDeprecated example
<?php
$rf = new ReflectionFunction('ereg');
var_dump($rf->isDeprecated());
?>
以上例程会输出:
bool(true)
参见
- <span class="methodname">ReflectionFunctionAbstract::getDocComment
ReflectionFunctionAbstract::isGenerator
判断函数是否是一个生成器函数
说明
public bool ReflectionFunctionAbstract::isGenerator ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
生成器函数返回 true,否则返回 false on failure.
ReflectionFunctionAbstract::isInternal
判断函数是否是内置函数
说明
public bool ReflectionFunctionAbstract::isInternal ( void )
判断函数是否是内置函数,与用户自定义函数相反
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
内置函数返回 true,否则返回 false
参见
- <span class="methodname">ReflectionFunctionAbstract::isUserDefined
ReflectionFunctionAbstract::isUserDefined
检查是否是用户定义
说明
public bool <span class="methodname">ReflectionFunctionAbstract::isUserDefined ( void )
检查函数是否是用户自定义,也就是说不是 PHP 自己内置函数
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
用户自定义函数返回 true,否则返回 false
参见
- <span class="methodname">ReflectionFunctionAbstract::isInternal
ReflectionFunctionAbstract::isVariadic
Checks if the function is variadic
说明
public bool ReflectionFunctionAbstract::isVariadic ( void )
Checks if the function is variadic.
参数
此函数没有参数。
返回值
Returns true if the function is variadic, otherwise false.
ReflectionFunctionAbstract::returnsReference
检查是否返回参考信息
说明
public bool <span class="methodname">ReflectionFunctionAbstract::returnsReference ( void )
检查是否返回参考信息
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
返回参考信息返回 true,否则返回 false
参见
- <span class="methodname">ReflectionFunctionAbstract::isClosure
ReflectionFunctionAbstract::__toString
字符串化
说明
abstract <span class="modifier">public void <span class="methodname">ReflectionFunctionAbstract::__toString ( void )
To string.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The string.
参见
- ReflectionClass::clone
- __toString()
简介
ReflectionMethod 类报告了一个方法的有关信息。
类摘要
ReflectionMethod
class ReflectionMethod <span class="ooclass"> extends ReflectionFunctionAbstract <span class="oointerface">implements <span class="interfacename">Reflector {
/* 常量 */
const integer
ReflectionMethod::IS_STATIC = 1 ;
const integer
ReflectionMethod::IS_PUBLIC = 256 ;
const integer
ReflectionMethod::IS_PROTECTED = 512
;
const integer
ReflectionMethod::IS_PRIVATE = 1024
;
const integer
ReflectionMethod::IS_ABSTRACT = 2 ;
const integer
ReflectionMethod::IS_FINAL = 4 ;
/* 属性 */
public $name ;
public $class ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">mixed $class ,
string
$name )
public <span
class="modifier">static string <span
class="methodname">export ( <span
class="type">string $class , <span
class="methodparam">string $name [,
bool $return<span
class="initializer"> = false ] )
public Closure
getClosure ( <span
class="methodparam">object $object )
public <span class="type">ReflectionClass <span class="methodname">getDeclaringClass ( <span class="methodparam">void )
public int <span class="methodname">getModifiers ( <span class="methodparam">void )
public <span class="type">ReflectionMethod <span class="methodname">getPrototype ( <span class="methodparam">void )
public mixed
invoke ( <span
class="type">object $object [, <span
class="methodparam">mixed $parameter
[, mixed
$... ]] )
public mixed
invokeArgs ( <span
class="methodparam">object $object ,
array $args
)
public bool isAbstract ( <span class="methodparam">void )
public bool isConstructor ( <span class="methodparam">void )
public bool isDestructor ( <span class="methodparam">void )
public bool isFinal ( <span class="methodparam">void )
public bool isPrivate ( <span class="methodparam">void )
public bool isProtected ( <span class="methodparam">void )
public bool isPublic ( <span class="methodparam">void )
public bool isStatic ( <span class="methodparam">void )
public void
setAccessible ( <span
class="methodparam">bool $accessible
)
public string __toString ( <span class="methodparam">void )
/* 继承的方法 */
final <span class="modifier">private void <span class="methodname">ReflectionFunctionAbstract::__clone ( <span class="methodparam">void )
public <span class="type">ReflectionClass <span class="methodname">ReflectionFunctionAbstract::getClosureScopeClass ( void )
public object <span class="methodname">ReflectionFunctionAbstract::getClosureThis ( void )
public string <span class="methodname">ReflectionFunctionAbstract::getDocComment ( void )
public int <span class="methodname">ReflectionFunctionAbstract::getEndLine ( <span class="methodparam">void )
public <span class="type">ReflectionExtension <span class="methodname">ReflectionFunctionAbstract::getExtension ( void )
public string <span class="methodname">ReflectionFunctionAbstract::getExtensionName ( void )
public string ReflectionFunctionAbstract::getFileName ( void )
public string ReflectionFunctionAbstract::getName ( void )
public string <span class="methodname">ReflectionFunctionAbstract::getNamespaceName ( void )
public int <span class="methodname">ReflectionFunctionAbstract::getNumberOfParameters ( void )
public int <span class="methodname">ReflectionFunctionAbstract::getNumberOfRequiredParameters ( void )
public array <span class="methodname">ReflectionFunctionAbstract::getParameters ( void )
public <span class="type">ReflectionType <span class="methodname">ReflectionFunctionAbstract::getReturnType ( void )
public string ReflectionFunctionAbstract::getShortName ( void )
public int <span class="methodname">ReflectionFunctionAbstract::getStartLine ( void )
public array <span class="methodname">ReflectionFunctionAbstract::getStaticVariables ( void )
public bool <span class="methodname">ReflectionFunctionAbstract::hasReturnType ( void )
public bool ReflectionFunctionAbstract::inNamespace ( void )
public bool ReflectionFunctionAbstract::isClosure ( void )
public bool ReflectionFunctionAbstract::isDeprecated ( void )
public bool ReflectionFunctionAbstract::isGenerator ( void )
public bool ReflectionFunctionAbstract::isInternal ( void )
public bool <span class="methodname">ReflectionFunctionAbstract::isUserDefined ( void )
public bool ReflectionFunctionAbstract::isVariadic ( void )
public bool <span class="methodname">ReflectionFunctionAbstract::returnsReference ( void )
abstract <span class="modifier">public void <span class="methodname">ReflectionFunctionAbstract::__toString ( void )
}
属性
name
Method name
class
Class name
预定义常量
ReflectionMethod 修饰符
ReflectionMethod::IS_STATIC
指示一个方法是静态(static)的。
ReflectionMethod::IS_PUBLIC
指示一个方法是 public 的。
ReflectionMethod::IS_PROTECTED
指示一个方法是 protected 的。
ReflectionMethod::IS_PRIVATE
指示一个方法是 private 的。
ReflectionMethod::IS_ABSTRACT
指示一个方法是 abstract 的。
ReflectionMethod::IS_FINAL
指示一个方法是 final 的。
ReflectionMethod::__construct
ReflectionMethod 的构造函数
说明
public <span
class="methodname">ReflectionMethod::__construct ( <span
class="methodparam">mixed $class ,
string
$name )
public <span
class="methodname">ReflectionMethod::__construct ( <span
class="methodparam">string
$class_method )
构造一个新的 ReflectionMethod
参数
class
包含方法的类名称或者这个类的一个实例
name
方法的名称
class_method
类名称和方法名称,之间使用 :: 分隔
返回值
没有返回值。
错误/异常
如果指定的方法不存在,那么抛出一个 <span class="classname">ReflectionException
范例
示例 #1 <span class="methodname">ReflectionMethod::__construct example
<?php
class Counter
{
private static $c = 0;
/**
* Increment counter
*
* @final
* @static
* @access public
* @return int
*/
final public static function increment()
{
return ++self::$c;
}
}
// Create an instance of the ReflectionMethod class
$method = new ReflectionMethod('Counter', 'increment');
// Print out basic information
printf(
"===> The %s%s%s%s%s%s%s method '%s' (which is %s)\n" .
" declared in %s\n" .
" lines %d to %d\n" .
" having the modifiers %d[%s]\n",
$method->isInternal() ? 'internal' : 'user-defined',
$method->isAbstract() ? ' abstract' : '',
$method->isFinal() ? ' final' : '',
$method->isPublic() ? ' public' : '',
$method->isPrivate() ? ' private' : '',
$method->isProtected() ? ' protected' : '',
$method->isStatic() ? ' static' : '',
$method->getName(),
$method->isConstructor() ? 'the constructor' : 'a regular method',
$method->getFileName(),
$method->getStartLine(),
$method->getEndline(),
$method->getModifiers(),
implode(' ', Reflection::getModifierNames($method->getModifiers()))
);
// 打印注释文档
printf("---> Documentation:\n %s\n", var_export($method->getDocComment(), 1));
// 打印存在的静态变量
if ($statics= $method->getStaticVariables()) {
printf("---> Static variables: %s\n", var_export($statics, 1));
}
// 执行方法
printf("---> Invocation results in: ");
var_dump($method->invoke(NULL));
?>
以上例程的输出类似于:
===> The user-defined final public static method 'increment' (which is a regular method)
declared in /Users/philip/cvs/phpdoc/test.php
lines 14 to 17
having the modifiers 261[final public static]
---> Documentation:
'/**
* Increment counter
*
* @final
* @static
* @access public
* @return int
*/'
---> Invocation results in: int(1)
参见
- ReflectionMethod::export
- Constructors
ReflectionMethod::export
输出一个回调方法
说明
public <span
class="modifier">static string <span
class="methodname">ReflectionMethod::export ( <span
class="methodparam">string $class ,
string
$name [, <span
class="type">bool $return =
false ] )
Exports a ReflectionMethod.
Warning
本函数还未编写文档,仅有参数列表。
参数
class
类名称
name
方法名称
return
设为 true 时返回导出结果,设为 false(默认值)则忽略返回。
返回值
如果参数 return 设为 true,导出结果将作为 <span
class="type">string 返回,否则返回 null。
参见
- ReflectionMethod::__construct
- ReflectionMethod::__toString
ReflectionMethod::getClosure
返回一个动态建立的方法调用接口,译者注:可以使用这个返回值直接调用非公开方法。
说明
public Closure
ReflectionMethod::getClosure ( <span
class="methodparam">object $object )
Warning
本函数还未编写文档,仅有参数列表。
参数
object
不可以使用静态方法,需要其他类型的方法
返回值
返回 Closure 如果产生任何错误返回
null
ReflectionMethod::getDeclaringClass
获取被反射的方法所在类的反射实例
说明
public <span class="type">ReflectionClass <span class="methodname">ReflectionMethod::getDeclaringClass ( <span class="methodparam">void )
获取被反射的方法所在的类的反射实例。
参数
此函数没有参数。
返回值
返回一个类的 ReflectionClass 反射对象,被反射的方法是这个类的一部分。
范例
示例 #1 <span class="methodname">ReflectionMethod::getDeclaringClass example
<?php
class HelloWorld {
protected function sayHelloTo($name) {
return 'Hello ' . $name;
}
}
$reflectionMethod = new ReflectionMethod(new HelloWorld(), 'sayHelloTo');
var_dump($reflectionMethod->getDeclaringClass());
?>
以上例程会输出:
object(ReflectionClass)#2 (1) {
["name"]=>
string(10) "HelloWorld"
}
参见
- ReflectionMethod::isAbstract
ReflectionMethod::getModifiers
获取方法的修饰符
说明
public int <span class="methodname">ReflectionMethod::getModifiers ( <span class="methodparam">void )
返回一个方法的修饰符,返回值是一个位标
参数
此函数没有参数。
返回值
使用一个数字表示方法修饰符,具体数字的含义可以参考 predefined constants 中的说明。
范例
示例 #1 <span class="methodname">ReflectionMethod::getModifiers example
<?php
class Testing
{
final public static function foo()
{
return;
}
public function bar()
{
return;
}
}
$foo = new ReflectionMethod('Testing', 'foo');
echo "Modifiers for method foo():\n";
echo $foo->getModifiers() . "\n";
echo implode(' ', Reflection::getModifierNames($foo->getModifiers())) . "\n";
$bar = new ReflectionMethod('Testing', 'bar');
echo "Modifiers for method bar():\n";
echo $bar->getModifiers() . "\n";
echo implode(' ', Reflection::getModifierNames($bar->getModifiers()));
?>
以上例程的输出类似于:
Modifiers for method foo():
261
final public static
Modifiers for method bar():
65792
public
参见
- Reflection::getModifierNames
ReflectionMethod::getPrototype
返回方法原型 (如果存在)
说明
public <span class="type">ReflectionMethod <span class="methodname">ReflectionMethod::getPrototype ( <span class="methodparam">void )
返回方法原型
参数
此函数没有参数。
返回值
方法原型的一个 ReflectionMethod 实例
错误/异常
如果方法没有原型,产生一个 <span class="classname">ReflectionException
范例
示例 #1 <span class="methodname">ReflectionMethod::getPrototype example
<?php
class Hello {
public function sayHelloTo($name) {
return 'Hello ' . $name;
}
}
class HelloWorld extends Hello {
public function sayHelloTo($name) {
return 'Hello world: ' . $name;
}
}
$reflectionMethod = new ReflectionMethod('HelloWorld', 'sayHelloTo');
var_dump($reflectionMethod->getPrototype());
?>
以上例程会输出:
object(ReflectionMethod)#2 (2) {
["name"]=>
string(10) "sayHelloTo"
["class"]=>
string(5) "Hello"
}
参见
- ReflectionMethod::getModifiers
ReflectionMethod::invoke
Invoke
说明
public mixed
ReflectionMethod::invoke ( <span
class="methodparam">object $object
[, mixed
$parameter [, <span
class="type">mixed $... ]] )
执行一个反射的方法。
参数
object
如果执行的方法是静态类,那么这个参数传送 <span
class="type">null。
parameter
0,或者传送给方法的参数列表。可以通过这个参数,给方法传送大量的参数。
返回值
返回方法的返回值
错误/异常
如果 object 并没有包含一个可以使用的类实例,那么将产生 一个 <span
class="classname">ReflectionException。
如果方法调用失败,也会产生一个 <span class="classname">ReflectionException。
范例
示例 #1 ReflectionMethod::invoke example
<?php
class HelloWorld {
public function sayHelloTo($name) {
return 'Hello ' . $name;
}
}
$reflectionMethod = new ReflectionMethod('HelloWorld', 'sayHelloTo');
echo $reflectionMethod->invoke(new HelloWorld(), 'Mike');
?>
以上例程会输出:
Hello Mike
注释
Note:
如果函数有参数需为引用,那么它们必须以引用方式传入。
参见
- ReflectionMethod::invokeArgs
- __invoke()
- call_user_func
ReflectionMethod::invokeArgs
带参数执行
说明
public mixed
ReflectionMethod::invokeArgs ( <span
class="methodparam">object $object ,
array $args
)
使用数组给方法传送参数,并执行他。
参数
object
调用方法的对象,如果是静态对象,设置为 null
args
使用 array 传送的方法参数。
返回值
返回方法返回值
错误/异常
如果 object 指定的实例无法执行方法,那么产生 <span
class="classname">ReflectionException 异常。
如果方法调用失败,产生 <span class="classname">ReflectionException
范例
示例 #1 ReflectionMethod::invokeArgs example
<?php
class HelloWorld {
public function sayHelloTo($name) {
return 'Hello ' . $name;
}
}
$reflectionMethod = new ReflectionMethod('HelloWorld', 'sayHelloTo');
echo $reflectionMethod->invokeArgs(new HelloWorld(), array('Mike'));
?>
以上例程会输出:
Hello Mike
注释
Note:
如果函数有参数需为引用,那么它们必须以引用方式传入。
参见
- ReflectionMethod::invoke
- __invoke()
- call_user_func_array
ReflectionMethod::isAbstract
判断方法是否是抽象方法
说明
public bool ReflectionMethod::isAbstract ( <span class="methodparam">void )
判断方法是否是抽象方法
参数
此函数没有参数。
返回值
如果是抽象方法返回 true,否则返回 false
参见
- ReflectionMethod::getDeclaringClass
ReflectionMethod::isConstructor
判断方法是否是构造方法
说明
public bool ReflectionMethod::isConstructor ( <span class="methodparam">void )
判断方法是否是构造方法
参数
此函数没有参数。
返回值
如果是构造方法返回 true,否则返回 false
参见
- ReflectionMethod::__construct
- ReflectionMethod::isAbstract
- ReflectionMethod::isDestructor
ReflectionMethod::isDestructor
判断方法是否是析构方法
说明
public bool ReflectionMethod::isDestructor ( <span class="methodparam">void )
判断方法是否是析构方法
参数
此函数没有参数。
返回值
如果是析构方法返回 true,否则返回 false
参见
- ReflectionMethod::isConstructor
ReflectionMethod::isFinal
判断方法是否定义 final
说明
public bool ReflectionMethod::isFinal ( <span class="methodparam">void )
判断方法是否定义 final
参数
此函数没有参数。
返回值
如果是 final 返回 true,否则返回 false
参见
- ReflectionMethod::isStatic
ReflectionMethod::isPrivate
判断方法是否是私有方法
说明
public bool ReflectionMethod::isPrivate ( <span class="methodparam">void )
判断方法是否是私有方法
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
私有方法返回 true,否则返回 false
参见
- ReflectionMethod::isPublic
ReflectionMethod::isProtected
判断方法是否是保护方法 (protected)
说明
public bool ReflectionMethod::isProtected ( <span class="methodparam">void )
判断方法是否是保护方法
参数
此函数没有参数。
返回值
保护方法返回 true,否则返回 false
参见
- ReflectionMethod::isPrivate
ReflectionMethod::isPublic
判断方法是否是公开方法
说明
public bool ReflectionMethod::isPublic ( <span class="methodparam">void )
判断方法是否是公开方法
参数
此函数没有参数。
返回值
公开方法返回 true,否则返回 false
参见
- ReflectionMethod::isPrivate
ReflectionMethod::isStatic
判断方法是否是静态方法
说明
public bool ReflectionMethod::isStatic ( <span class="methodparam">void )
判断方法是否是静态方法
参数
此函数没有参数。
返回值
静态方法返回 true,否则返回 false
参见
- ReflectionMethod::isFinal
ReflectionMethod::setAccessible
设置方法是否访问
说明
public void
ReflectionMethod::setAccessible ( <span
class="methodparam">bool $accessible
)
设置方法是否可以访问,例如通过设置可以访问能够执行私有方法和保护方法
参数
accessible
可以访问设置 true,否则设置 false
返回值
没有返回值。
参见
- ReflectionMethod::isPrivate
- ReflectionMethod::isProtected
ReflectionMethod::__toString
返回反射方法对象的字符串表达
说明
public string ReflectionMethod::__toString ( <span class="methodparam">void )
返回反射方法对象的字符串表达
参数
此函数没有参数。
返回值
ReflectionMethod 实例的字符串表达,也就是字符串
范例
示例 #1 <span class="methodname">ReflectionMethod::__toString example
<?php
class HelloWorld {
public function sayHelloTo($name) {
return 'Hello ' . $name;
}
}
$reflectionMethod = new ReflectionMethod(new HelloWorld(), 'sayHelloTo');
echo $reflectionMethod;
?>
以上例程会输出:
Method [ <user> public method sayHelloTo ] {
@@ /var/www/examples/reflection.php 16 - 18
- Parameters [1] {
Parameter #0 [ <required> $name ]
}
}
参见
- ReflectionMethod::export
- __toString()
简介
ReflectionObject 类报告了一个对象(<span class="type">object)的相关信息。
类摘要
ReflectionObject
class ReflectionObject <span class="ooclass"> extends ReflectionClass implements <span class="interfacename">Reflector {
/* 常量 */
const integer
ReflectionObject::IS_IMPLICIT_ABSTRACT =
16 ;
const integer
ReflectionObject::IS_EXPLICIT_ABSTRACT =
32 ;
const integer
ReflectionObject::IS_FINAL = 64 ;
/* 属性 */
public $name ;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">object $argument
)
public <span
class="modifier">static string <span
class="methodname">export ( <span
class="type">string $argument [, <span
class="methodparam">bool $return ] )
/* 继承的方法 */
public <span
class="methodname">ReflectionClass::__construct ( <span
class="methodparam">mixed $argument )
public <span
class="modifier">static string <span
class="methodname">ReflectionClass::export ( <span
class="methodparam">mixed $argument
[, bool
$return = false ] )
public mixed
ReflectionClass::getConstant ( <span
class="methodparam">string $name )
public array ReflectionClass::getConstants ( <span class="methodparam">void )
public <span class="type">ReflectionMethod <span class="methodname">ReflectionClass::getConstructor ( <span class="methodparam">void )
public array ReflectionClass::getDefaultProperties ( void )
public string ReflectionClass::getDocComment ( <span class="methodparam">void )
public int <span class="methodname">ReflectionClass::getEndLine ( <span class="methodparam">void )
public <span class="type">ReflectionExtension <span class="methodname">ReflectionClass::getExtension ( <span class="methodparam">void )
public string ReflectionClass::getExtensionName ( void )
public string ReflectionClass::getFileName ( <span class="methodparam">void )
public array ReflectionClass::getInterfaceNames ( void )
public array ReflectionClass::getInterfaces ( <span class="methodparam">void )
public <span
class="type">ReflectionMethod <span
class="methodname">ReflectionClass::getMethod ( <span
class="methodparam">string $name )
public array
ReflectionClass::getMethods ([ <span
class="methodparam">int $filter ] )
public int <span class="methodname">ReflectionClass::getModifiers ( <span class="methodparam">void )
public string ReflectionClass::getName ( <span class="methodparam">void )
public string ReflectionClass::getNamespaceName ( void )
public <span class="type">ReflectionClass <span class="methodname">ReflectionClass::getParentClass ( <span class="methodparam">void )
public array
ReflectionClass::getProperties ([ <span
class="methodparam">int $filter ] )
public <span
class="type">ReflectionProperty <span
class="methodname">ReflectionClass::getProperty ( <span
class="methodparam">string $name )
public <span
class="type">ReflectionClassConstant<span
class="type">false <span
class="methodname">ReflectionClass::getReflectionConstant ( <span
class="methodparam">string $name )
public array ReflectionClass::getReflectionConstants ( void )
public string ReflectionClass::getShortName ( <span class="methodparam">void )
public int <span class="methodname">ReflectionClass::getStartLine ( <span class="methodparam">void )
public array ReflectionClass::getStaticProperties ( void )
public mixed
ReflectionClass::getStaticPropertyValue
( string
$name [, <span
class="type">mixed &$def_value ] )
public array ReflectionClass::getTraitAliases ( <span class="methodparam">void )
public array ReflectionClass::getTraitNames ( <span class="methodparam">void )
public array ReflectionClass::getTraits ( <span class="methodparam">void )
public bool
ReflectionClass::hasConstant ( <span
class="methodparam">string $name )
public bool
ReflectionClass::hasMethod ( <span
class="methodparam">string $name )
public bool
ReflectionClass::hasProperty ( <span
class="methodparam">string $name )
public bool
ReflectionClass::implementsInterface (
string
$interface )
public bool ReflectionClass::inNamespace ( <span class="methodparam">void )
public bool ReflectionClass::isAbstract ( <span class="methodparam">void )
public bool ReflectionClass::isAnonymous ( <span class="methodparam">void )
public bool ReflectionClass::isCloneable ( <span class="methodparam">void )
public bool ReflectionClass::isFinal ( <span class="methodparam">void )
public bool
ReflectionClass::isInstance ( <span
class="methodparam">object $object )
public bool ReflectionClass::isInstantiable ( <span class="methodparam">void )
public bool ReflectionClass::isInterface ( <span class="methodparam">void )
public bool ReflectionClass::isInternal ( <span class="methodparam">void )
public bool ReflectionClass::isIterable ( <span class="methodparam">void )
public bool ReflectionClass::isIterateable ( <span class="methodparam">void )
public bool
ReflectionClass::isSubclassOf ( <span
class="methodparam">string $class )
public bool ReflectionClass::isTrait ( <span class="methodparam">void )
public bool ReflectionClass::isUserDefined ( <span class="methodparam">void )
public object
ReflectionClass::newInstance ( <span
class="methodparam">mixed $args [,
mixed $...
] )
public object
ReflectionClass::newInstanceArgs ([
array $args
] )
public object <span class="methodname">ReflectionClass::newInstanceWithoutConstructor ( void )
public void
ReflectionClass::setStaticPropertyValue
( string
$name , <span
class="type">string $value )
public string ReflectionClass::__toString ( <span class="methodparam">void )
}
属性
name
对象的类名。只读,在尝试赋值的时候会抛出 <span
class="classname">ReflectionException。
ReflectionObject::__construct
Constructs a ReflectionObject
说明
public <span
class="methodname">ReflectionObject::__construct ( <span
class="methodparam">object $argument
)
Constructs a ReflectionObject.
Warning
本函数还未编写文档,仅有参数列表。
参数
argument
An object instance.
返回值
没有返回值。
参见
- ReflectionObject::export
- Constructors
ReflectionObject::export
Export
说明
public <span
class="modifier">static string <span
class="methodname">ReflectionObject::export ( <span
class="methodparam">string $argument
[, bool
$return ] )
Exports a reflection.
Warning
本函数还未编写文档,仅有参数列表。
参数
argument
导出的反射。
return
设为 true 时返回导出结果,设为 false(默认值)则忽略返回。
返回值
如果参数 return 设为 true,导出结果将作为 <span
class="type">string 返回,否则返回 null。
参见
- ReflectionObject::__construct
简介
ReflectionParameter 取回了函数或方法参数的相关信息。
要自行检查函数的参数,首先创建一个 <span class="classname">ReflectionFunction 或 <span class="classname">ReflectionMethod 的实例,然后使用它们的 <span class="methodname">ReflectionFunctionAbstract::getParameters 方法来获取参数的数组。
类摘要
ReflectionParameter
class ReflectionParameter <span class="oointerface">implements <span class="interfacename">Reflector {
/* 属性 */
public $name ;
/* 方法 */
public bool allowsNull ( <span class="methodparam">void )
public bool canBePassedByValue ( <span class="methodparam">void )
final <span class="modifier">private void <span class="methodname">__clone ( <span class="methodparam">void )
public <span
class="methodname">__construct ( <span
class="methodparam">callable
$function , <span
class="type">mixed $parameter )
public <span
class="modifier">static string <span
class="methodname">export ( <span
class="type">string $function , <span
class="methodparam">string $parameter
[, bool
$return ] )
public <span class="type">ReflectionClass <span class="methodname">getClass ( <span class="methodparam">void )
public <span class="type">ReflectionClass <span class="methodname">getDeclaringClass ( <span class="methodparam">void )
public <span class="type">ReflectionFunctionAbstract <span class="methodname">getDeclaringFunction ( <span class="methodparam">void )
public mixed getDefaultValue ( <span class="methodparam">void )
public string getDefaultValueConstantName ( <span class="methodparam">void )
public string getName ( <span class="methodparam">void )
public int <span class="methodname">getPosition ( <span class="methodparam">void )
public <span class="type">ReflectionType <span class="methodname">getType ( <span class="methodparam">void )
public bool hasType ( <span class="methodparam">void )
public bool isArray ( <span class="methodparam">void )
public bool isCallable ( <span class="methodparam">void )
public bool isDefaultValueAvailable ( <span class="methodparam">void )
public bool isDefaultValueConstant ( <span class="methodparam">void )
public bool isOptional ( <span class="methodparam">void )
public bool isPassedByReference ( <span class="methodparam">void )
public bool isVariadic ( <span class="methodparam">void )
public string __toString ( <span class="methodparam">void )
}
属性
name
参数的名称。只读,在尝试赋值的时候会抛出 <span
class="classname">ReflectionException。
ReflectionParameter::allowsNull
Checks if null is allowed
说明
public bool ReflectionParameter::allowsNull ( <span class="methodparam">void )
Checks whether the parameter allows null.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
true if null is allowed, otherwise false
参见
- ReflectionParameter::isOptional
ReflectionParameter::canBePassedByValue
Returns whether this parameter can be passed by value
说明
public bool ReflectionParameter::canBePassedByValue ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Returns true if the parameter can be passed by value, false
otherwise. Returns null in case of an error.
ReflectionParameter::__clone
Clone
说明
final <span class="modifier">private void <span class="methodname">ReflectionParameter::__clone ( <span class="methodparam">void )
Clones.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
参见
- ReflectionParameter::toString
- Object cloning
ReflectionParameter::__construct
Construct
说明
public <span
class="methodname">ReflectionParameter::__construct ( <span
class="methodparam">callable
$function , <span
class="type">mixed $parameter )
Constructs a ReflectionParameter instance.
参数
function
The function to reflect parameters from.
parameter
Either an int specifying the position of the
parameter (starting with zero), or a the parameter name as <span
class="type">string.
返回值
没有返回值。
范例
示例 #1 Using the ReflectionParameter class
<?php
function foo($a, $b, $c) { }
function bar(Exception $a, &$b, $c) { }
function baz(ReflectionFunction $a, $b = 1, $c = null) { }
function abc() { }
$reflect = new ReflectionFunction('foo');
echo $reflect;
foreach ($reflect->getParameters() as $i => $param) {
printf(
"-- Parameter #%d: %s {\n".
" Class: %s\n".
" Allows NULL: %s\n".
" Passed to by reference: %s\n".
" Is optional?: %s\n".
"}\n",
$i, // $param->getPosition() can be used from PHP 5.2.3
$param->getName(),
var_export($param->getClass(), 1),
var_export($param->allowsNull(), 1),
var_export($param->isPassedByReference(), 1),
$param->isOptional() ? 'yes' : 'no'
);
}
?>
以上例程的输出类似于:
Function [ <user> function foo ] {
@@ /Users/philip/cvs/phpdoc/a 2 - 2
- Parameters [3] {
Parameter #0 [ <required> $a ]
Parameter #1 [ <required> $b ]
Parameter #2 [ <required> $c ]
}
}
-- Parameter #0: a {
Class: NULL
Allows NULL: true
Passed to by reference: false
Is optional?: no
}
-- Parameter #1: b {
Class: NULL
Allows NULL: true
Passed to by reference: false
Is optional?: no
}
-- Parameter #2: c {
Class: NULL
Allows NULL: true
Passed to by reference: false
Is optional?: no
}
参见
- <span class="methodname">ReflectionFunctionAbstract::getParameters
- ReflectionFunction::__construct
- ReflectionMethod::__construct
- Constructors
ReflectionParameter::export
Exports
Warning
本函数已自 PHP 7.4.0 起废弃。强烈建议不要使用本函数。
说明
public <span
class="modifier">static string <span
class="methodname">ReflectionParameter::export ( <span
class="methodparam">string $function
, string
$parameter [, <span
class="type">bool $return ] )
Exports.
Warning
本函数还未编写文档,仅有参数列表。
参数
function
The function name.
parameter
The parameter name.
return
设为 true 时返回导出结果,设为 false(默认值)则忽略返回。
返回值
The exported reflection.
参见
- ReflectionParameter::__toString
ReflectionParameter::getClass
获得类型提示类。
说明
public <span class="type">ReflectionClass <span class="methodname">ReflectionParameter::getClass ( <span class="methodparam">void )
获取参数的类型提示类,类型为<span class="classname">ReflectionClass对象。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
一个 ReflectionClass 对象。
范例
示例 #1 使用 ReflectionParameter 类
<?php
function foo(Exception $a) { }
$functionReflection = new ReflectionFunction('foo');
$parameters = $functionReflection->getParameters();
$aParameter = $parameters[0];
echo $aParameter->getClass()->name;
?>
以上例程会输出:
Exception
参见
- <span class="methodname">ReflectionParameter::getDeclaringClass
ReflectionParameter::getDeclaringClass
Gets declaring class
说明
public <span class="type">ReflectionClass <span class="methodname">ReflectionParameter::getDeclaringClass ( <span class="methodparam">void )
Gets the declaring class.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
A ReflectionClass object or null if
called on function.
范例
示例 #1 Getting the class that declared the method
<?php
class Foo
{
public function bar(\DateTime $datetime)
{
}
}
class Baz extends Foo
{
}
$param = new \ReflectionParameter(['Baz', 'bar'], 0);
var_dump($param->getDeclaringClass());
以上例程会输出:
object(ReflectionClass)#2 (1) {
["name"]=>
string(3) "Foo"
}
参见
- ReflectionParameter::getClass
ReflectionParameter::getDeclaringFunction
Gets declaring function
说明
public <span class="type">ReflectionFunctionAbstract <span class="methodname">ReflectionParameter::getDeclaringFunction ( void )
Gets the declaring function.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
A ReflectionFunction object.
参见
- <span class="methodname">ReflectionParameter::getDeclaringClass
ReflectionParameter::getDefaultValue
Gets default parameter value
说明
public mixed ReflectionParameter::getDefaultValue ( void )
Gets the default value of the parameter for any user-defined or internal function or method. If the parameter is not optional a <span class="classname">ReflectionException will be thrown.
参数
此函数没有参数。
返回值
The parameters default value.
更新日志
| 版本 | 说明 |
|---|---|
| 8.0.0 | This method now allows getting the default value of parameters of built-in functions and built-in class methods. Previously, a ReflectionException was thrown. |
范例
示例 #1 Getting default values of function parameters
<?php
function foo($test, $bar = 'baz')
{
echo $test . $bar;
}
$function = new ReflectionFunction('foo');
foreach ($function->getParameters() as $param) {
echo 'Name: ' . $param->getName() . PHP_EOL;
if ($param->isOptional()) {
echo 'Default value: ' . $param->getDefaultValue() . PHP_EOL;
}
echo PHP_EOL;
}
?>
以上例程会输出:
Name: test
Name: bar
Default value: baz
参见
- ReflectionParameter::isOptional
- <span class="methodname">ReflectionParameter::isDefaultValueAvailable
- <span class="methodname">ReflectionParameter::getDefaultValueConstantName
- <span class="methodname">ReflectionParameter::isPassedByReference
ReflectionParameter::getDefaultValueConstantName
Returns the default value's constant name if default value is constant or null
说明
public string <span class="methodname">ReflectionParameter::getDefaultValueConstantName ( void )
Returns the default value's constant name of the parameter of any user-defined or internal function or method, if default value is constant or null. If the parameter is not optional a <span class="classname">ReflectionException will be thrown.
参数
此函数没有参数。
返回值
Returns string on success or null on failure.
更新日志
| 版本 | 说明 |
|---|---|
| 8.0.0 | This method now allows getting the default values' constant names of built-in functions and built-in class methods. Previously, a ReflectionException was thrown. |
范例
示例 #1 Getting default values' constant names of function parameters
<?php
function foo($test, $bar = PHP_INT_MIN)
{
echo $test . $bar;
}
$function = new ReflectionFunction('foo');
foreach ($function->getParameters() as $param) {
echo 'Name: ' . $param->getName() . PHP_EOL;
if ($param->isOptional()) {
echo 'Default value: ' . $param->getDefaultValueConstantName() . PHP_EOL;
}
echo PHP_EOL;
}
?>
以上例程会输出:
Name: test
Name: bar
Default value: PHP_INT_MIN
参见
- ReflectionParameter::isOptional
- <span class="methodname">ReflectionParameter::isDefaultValueConstant
- ReflectionParameter::getDefaultValue
ReflectionParameter::getName
Gets parameter name
说明
public string ReflectionParameter::getName ( <span class="methodparam">void )
Gets the name of the parameter.
参数
此函数没有参数。
返回值
The name of the reflected parameter.
参见
- ReflectionParameter::getValue
ReflectionParameter::getPosition
Gets parameter position
说明
public int <span class="methodname">ReflectionParameter::getPosition ( <span class="methodparam">void )
Gets the position of the parameter.
参数
此函数没有参数。
返回值
The position of the parameter, left to right, starting at position #0.
参见
- ReflectionParameter::getName
ReflectionParameter::getType
Gets a parameter's type
说明
public <span class="type">ReflectionType <span class="methodname">ReflectionParameter::getType ( <span class="methodparam">void )
Gets the associated type of a parameter.
参数
此函数没有参数。
返回值
Returns a ReflectionType object if a
parameter type is specified, null otherwise.
范例
示例 #1 ReflectionParameter::getType Usage as of PHP 7.1.0
As of PHP 7.1.0, <span class="methodname">ReflectionType::__toString is deprecated, and ReflectionParameter::getType may return an instance of <span class="classname">ReflectionNamedType. To get the name of the parameter type, ReflectionNamedType is available in this case.
<?php
function someFunction(int $param, $param2) {}
$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();
$reflectionType1 = $reflectionParams[0]->getType();
$reflectionType2 = $reflectionParams[1]->getType();
assert($reflectionType1 instanceof ReflectionNamedType);
echo $reflectionType1->getName(), PHP_EOL;
var_dump($reflectionType2);
?>
以上例程会输出:
int
NULL
示例 #2 ReflectionParameter::getType Usage before PHP 7.1.0
<?php
function someFunction(int $param, $param2) {}
$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();
$reflectionType1 = $reflectionParams[0]->getType();
$reflectionType2 = $reflectionParams[1]->getType();
echo $reflectionType1, PHP_EOL;
var_dump($reflectionType2);
?>
以上例程在 PHP 7.0 中的输出:
int
NULL
参见
- ReflectionParameter::hasType
- ReflectionType::__toString
ReflectionParameter::hasType
Checks if parameter has a type
说明
public bool ReflectionParameter::hasType ( <span class="methodparam">void )
Checks if the parameter has a type associated with it.
参数
此函数没有参数。
返回值
true if a type is specified, false otherwise.
范例
示例 #1 ReflectionParameter::hasType example
<?php
function someFunction(string $param, $param2 = null) {}
$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();
var_dump($reflectionParams[0]->hasType());
var_dump($reflectionParams[1]->hasType());
以上例程的输出类似于:
bool(true)
bool(false)
参见
- ReflectionParameter::getType
ReflectionParameter::isArray
Checks if parameter expects an array
说明
public bool ReflectionParameter::isArray ( <span class="methodparam">void )
Checks if the parameter expects an array.
参数
此函数没有参数。
返回值
true if an array is expected,
false otherwise.
参见
- ReflectionParameter::isOptional
ReflectionParameter::isCallable
Returns whether parameter MUST be callable
说明
public bool ReflectionParameter::isCallable ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Returns true if the parameter is <span
class="type">callable, false if it is not or null on
failure.
ReflectionParameter::isDefaultValueAvailable
检查是否有默认值。
说明
public bool <span class="methodname">ReflectionParameter::isDefaultValueAvailable ( void )
检查参数是否有默认值。
参数
此函数没有参数。
返回值
如果有默认值返回,true if a default value is available, 否则返回
false
参见
- ReflectionParameter::getDefaultValue
- ReflectionParameter::getName
ReflectionParameter::isDefaultValueConstant
Returns whether the default value of this parameter is a constant
说明
public bool <span class="methodname">ReflectionParameter::isDefaultValueConstant ( void )
Returns whether the default value of this parameter is a constant.
参数
此函数没有参数。
返回值
Returns true if the default value is constant, and false
otherwise.
参见
- <span class="methodname">ReflectionParameter::getDefaultValueConstantName
- <span class="methodname">ReflectionParameter::isDefaultValueAvailable
ReflectionParameter::isOptional
Checks if optional
说明
public bool ReflectionParameter::isOptional ( <span class="methodparam">void )
Checks if the parameter is optional.
参数
此函数没有参数。
返回值
true if the parameter is optional, otherwise false
参见
- ReflectionParameter::getName
ReflectionParameter::isPassedByReference
Checks if passed by reference
说明
public bool ReflectionParameter::isPassedByReference ( void )
Checks if the parameter is passed in by reference.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
true if the parameter is passed in by reference, otherwise
false
参见
- ReflectionParameter::getName
ReflectionParameter::isVariadic
Checks if the parameter is variadic
说明
public bool ReflectionParameter::isVariadic ( <span class="methodparam">void )
Checks if the parameter was declared as a variadic parameter.
参数
此函数没有参数。
返回值
Returns true if the parameter is variadic, otherwise false.
ReflectionParameter::__toString
To string
说明
public string ReflectionParameter::__toString ( void )
To string.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
参见
- ReflectionParameter::export
- __toString()
简介
ReflectionProperty 类报告了类的属性的相关信息。
类摘要
ReflectionProperty
class ReflectionProperty <span class="oointerface">implements <span class="interfacename">Reflector {
/* 常量 */
const integer
ReflectionProperty::IS_STATIC = 1 ;
const integer
ReflectionProperty::IS_PUBLIC = 256
;
const integer
ReflectionProperty::IS_PROTECTED =
512 ;
const integer
ReflectionProperty::IS_PRIVATE =
1024 ;
/* 属性 */
public $name ;
public $class ;
/* 方法 */
final <span class="modifier">private void <span class="methodname">__clone ( <span class="methodparam">void )
public <span
class="methodname">__construct ( <span
class="methodparam">mixed $class ,
string
$name )
public <span
class="modifier">static string <span
class="methodname">export ( <span
class="type">mixed $class , <span
class="methodparam">string $name [,
bool
$return ] )
public <span class="type">ReflectionClass <span class="methodname">getDeclaringClass ( <span class="methodparam">void )
public mixed getDefaultValue ( <span class="methodparam">void )
public string getDocComment ( <span class="methodparam">void )
public int <span class="methodname">getModifiers ( <span class="methodparam">void )
public string getName ( <span class="methodparam">void )
public <span class="type">ReflectionTypenull getType ( <span class="methodparam">void )
public mixed
getValue ([ <span
class="methodparam">object $object ]
)
public bool hasDefaultValue ( <span class="methodparam">void )
public bool hasType ( <span class="methodparam">void )
public bool isDefault ( <span class="methodparam">void )
public bool
isInitialized ([ <span
class="methodparam">object $object ]
)
public bool isPrivate ( <span class="methodparam">void )
public bool isProtected ( <span class="methodparam">void )
public bool isPublic ( <span class="methodparam">void )
public bool isStatic ( <span class="methodparam">void )
public void
setAccessible ( <span
class="methodparam">bool $accessible
)
public void
setValue ( <span
class="methodparam">object $object ,
mixed
$value )
public string __toString ( <span class="methodparam">void )
}
属性
name
属性的名称。只读,在尝试赋值的时候抛出 <span
class="classname">ReflectionException。
class
定义的属性所在的类。只读,在尝试赋值的时候抛出 <span
class="classname">ReflectionException。
预定义常量
ReflectionProperty 修饰符
ReflectionProperty::IS_STATIC
指示了 static
的属性。
ReflectionProperty::IS_PUBLIC
指示了 public
的属性。
ReflectionProperty::IS_PROTECTED
指示了
protected
的属性。
ReflectionProperty::IS_PRIVATE
指示了 private
的属性。
ReflectionProperty::__clone
Clone
说明
final <span class="modifier">private void <span class="methodname">ReflectionProperty::__clone ( <span class="methodparam">void )
Clones.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
参见
- ReflectionProperty::export
- Object cloning
ReflectionProperty::__construct
Construct a ReflectionProperty object
说明
public <span
class="methodname">ReflectionProperty::__construct ( <span
class="methodparam">mixed $class ,
string
$name )
Warning
本函数还未编写文档,仅有参数列表。
参数
class
The class name, that contains the property.
name
The name of the property being reflected.
返回值
没有返回值。
错误/异常
Trying to get or set private or protected class property's values will result in an exception being thrown.
范例
示例 #1 <span class="methodname">ReflectionProperty::__construct example
<?php
class Str
{
public $length = 5;
}
// Create an instance of the ReflectionProperty class
$prop = new ReflectionProperty('Str', 'length');
// Print out basic information
printf(
"===> The%s%s%s%s property '%s' (which was %s)\n" .
" having the modifiers %s\n",
$prop->isPublic() ? ' public' : '',
$prop->isPrivate() ? ' private' : '',
$prop->isProtected() ? ' protected' : '',
$prop->isStatic() ? ' static' : '',
$prop->getName(),
$prop->isDefault() ? 'declared at compile-time' : 'created at run-time',
var_export(Reflection::getModifierNames($prop->getModifiers()), 1)
);
// Create an instance of Str
$obj= new Str();
// Get current value
printf("---> Value is: ");
var_dump($prop->getValue($obj));
// Change value
$prop->setValue($obj, 10);
printf("---> Setting value to 10, new value is: ");
var_dump($prop->getValue($obj));
// Dump object
var_dump($obj);
?>
以上例程的输出类似于:
===> The public property 'length' (which was declared at compile-time)
having the modifiers array (
0 => 'public',
)
---> Value is: int(5)
---> Setting value to 10, new value is: int(10)
object(Str)#2 (1) {
["length"]=>
int(10)
}
示例 #2 Getting value from private and protected properties using ReflectionProperty class
<?php
class Foo {
public $x = 1;
protected $y = 2;
private $z = 3;
}
$obj = new Foo;
$prop = new ReflectionProperty('Foo', 'y');
$prop->setAccessible(true); /* As of PHP 5.3.0 */
var_dump($prop->getValue($obj)); // int(2)
$prop = new ReflectionProperty('Foo', 'z');
$prop->setAccessible(true); /* As of PHP 5.3.0 */
var_dump($prop->getValue($obj)); // int(2)
?>
以上例程的输出类似于:
int(2)
int(3)
参见
- ReflectionProperty::getName
- Constructors
ReflectionProperty::export
Export
说明
public <span
class="modifier">static string <span
class="methodname">ReflectionProperty::export ( <span
class="methodparam">mixed $class ,
string
$name [, <span
class="type">bool $return ] )
Exports a reflection.
Warning
本函数还未编写文档,仅有参数列表。
参数
argument
导出的反射。
name
The property name.
return
设为 true 时返回导出结果,设为 false(默认值)则忽略返回。
返回值
参见
- ReflectionProperty::__toString
ReflectionProperty::getDeclaringClass
Gets declaring class
说明
public <span class="type">ReflectionClass <span class="methodname">ReflectionProperty::getDeclaringClass ( <span class="methodparam">void )
Gets the declaring class.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
A ReflectionClass object.
参见
- ReflectionProperty::getName
ReflectionProperty::getDefaultValue
Returns the default value declared for a property
说明
public mixed ReflectionProperty::getDefaultValue ( void )
Gets the implicit or explicitly declared default value for a property.
参数
此函数没有参数。
返回值
The default value if the property has any default value (including
null). If there is no default value, then null is returned.
It is not possible to differentiate between a null default value
and an unitialized typed property. Use <span
class="methodname">ReflectionClass::hasDefaultValue to detect the
difference.
范例
示例 #1 <span class="methodname">ReflectionClass::getDefaultValue example
<?php
class Foo {
public $bar = 1;
public ?int $baz;
public int $boing = 0;
}
$ro = new ReflectionClass(Foo::class);
var_dump($ro->getProperty('bar')->getDefaultValue());
var_dump($ro->getProperty('baz')->getDefaultValue());
var_dump($ro->getProperty('boing')->getDefaultValue());
?>
以上例程会输出:
int(1)
NULL
int(0)
参见
- ReflectionProperty::hasDefaultValue
ReflectionProperty::getDocComment
Gets the property doc comment
说明
public string ReflectionProperty::getDocComment ( void )
Gets the doc comment for a property.
参数
此函数没有参数。
返回值
The property doc comment.
范例
示例 #1 <span class="methodname">ReflectionProperty::getDocComment example
<?php
class Str
{
/**
* @var int The length of the string
*/
public $length = 5;
}
$prop = new ReflectionProperty('Str', 'length');
var_dump($prop->getDocComment());
?>
以上例程的输出类似于:
string(53) "/**
* @var int The length of the string
*/"
示例 #2 Multiple property declarations
If multiple property declarations are preceeded by a single doc comment, the doc comment refers to the first property only.
<?php
class Foo
{
/** @var string */
public $a, $b;
}
$class = new \ReflectionClass('Foo');
foreach ($class->getProperties() as $property) {
echo $property->getName() . ': ' . var_export($property->getDocComment(), true) . PHP_EOL;
}
?>
以上例程会输出:
a: '/** @var string */'
b: false
参见
- ReflectionProperty::getModifiers
- ReflectionProperty::getName
- ReflectionProperty::getValue
ReflectionProperty::getModifiers
Gets the property modifiers
说明
public int <span class="methodname">ReflectionProperty::getModifiers ( <span class="methodparam">void )
Gets the modifiers.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
A numeric representation of the modifiers.
参见
- ReflectionProperty::isPrivate
- Reflection::getModifierNames
ReflectionProperty::getName
Gets property name
说明
public string ReflectionProperty::getName ( <span class="methodparam">void )
Gets the properties name.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
The name of the reflected property.
参见
- ReflectionProperty::getValue
ReflectionProperty::getType
Gets a property's type
说明
public <span class="type">ReflectionTypenull ReflectionProperty::getType ( <span class="methodparam">void )
Gets the associated type of a property.
参数
此函数没有参数。
返回值
Returns a ReflectionType if the property
has a type, and null otherwise.
范例
示例 #1 ReflectionProperty::getType example
<?php
class User
{
public string $name;
}
$rp = new ReflectionProperty('User', 'name');
echo $rp->getType()->getName();
?>
以上例程会输出:
string
参见
- ReflectionProperty::hasType
- ReflectionProperty::isInitialized
ReflectionProperty::getValue
Gets value
说明
public mixed
ReflectionProperty::getValue ([ <span
class="methodparam">object $object ]
)
Gets the property's value.
参数
object
If the property is non-static an object must be provided to fetch the
property from. If you want to fetch the default property without
providing an object use <span
class="methodname">ReflectionClass::getDefaultProperties instead.
返回值
The current value of the property.
错误/异常
Throws a ReflectionException if the property is inaccessible. You can make a protected or private property accessible using <span class="methodname">ReflectionProperty::setAccessible.
范例
示例 #1 ReflectionProperty::getValue example
<?php
class Foo {
public static $staticProperty = 'foobar';
public $property = 'barfoo';
protected $privateProperty = 'foofoo';
}
$reflectionClass = new ReflectionClass('Foo');
var_dump($reflectionClass->getProperty('staticProperty')->getValue());
var_dump($reflectionClass->getProperty('property')->getValue(new Foo));
$reflectionProperty = $reflectionClass->getProperty('privateProperty');
$reflectionProperty->setAccessible(true);
var_dump($reflectionProperty->getValue(new Foo));
?>
以上例程会输出:
string(6) "foobar"
string(6) "barfoo"
string(6) "foofoo"
参见
- ReflectionProperty::setValue
- ReflectionProperty::setAccessible
- <span class="methodname">ReflectionClass::getDefaultProperties
- <span class="methodname">ReflectionClass::getStaticPropertyValue
ReflectionProperty::hasDefaultValue
Checks if property has a default value declared
说明
public bool ReflectionProperty::hasDefaultValue ( void )
Checks whether the property was declared with a default value, including
an implicit null default value. Only returns false for typed
properties without default value (or dynamic properties).
参数
此函数没有参数。
返回值
If the property has any default value (including null) true
is returned; if the property is typed without a default value declared
or is a dynamic property, false is returned.
范例
示例 #1 <span class="methodname">ReflectionClass::hasDefaultValue example
<?php
class Foo {
public $bar;
public ?int $baz;
public int $boing;
}
$ro = new ReflectionClass(Foo::class);
var_dump($ro->getProperty('bar')->hasDefaultValue());
var_dump($ro->getProperty('baz')->hasDefaultValue());
var_dump($ro->getProperty('boing')->hasDefaultValue());
?>
以上例程会输出:
bool(true)
bool(false)
bool(false)
参见
- ReflectionProperty::getDefaultValue
ReflectionProperty::hasType
Checks if property has a type
说明
public bool ReflectionProperty::hasType ( <span class="methodparam">void )
Checks if the property has a type associated with it.
参数
此函数没有参数。
返回值
true if a type is specified, false otherwise.
范例
示例 #1 ReflectionProperty::hasType example
<?php
class User
{
public string $name;
}
$rp = new ReflectionProperty('User', 'name');
var_dump($rp->hasType());
?>
以上例程会输出:
bool(true)
参见
- ReflectionProperty::getType
- ReflectionProperty::isInitialized
ReflectionProperty::isDefault
Checks if property is a default property
说明
public bool ReflectionProperty::isDefault ( <span class="methodparam">void )
Checks whether the property was declared at compile-time, or whether the property was dynamically declared at run-time.
参数
此函数没有参数。
返回值
true if the property was declared at compile-time, or false
if it was created at run-time.
范例
示例 #1 ReflectionClass::isDefault example
<?php
class Foo {
public $bar;
}
$o = new Foo();
$o->bar = 42;
$o->baz = 42;
$ro = new ReflectionObject($o);
var_dump($ro->getProperty('bar')->isDefault());
var_dump($ro->getProperty('baz')->isDefault());
?>
以上例程会输出:
bool(true)
bool(false)
参见
- ReflectionProperty::getValue
ReflectionProperty::isInitialized
Checks whether a property is initialized
说明
public bool
ReflectionProperty::isInitialized ([
object
$object ] )
Checks whether a property is initialized.
参数
object
If the property is non-static an object must be provided to fetch the
property from.
返回值
Returns false for typed properties prior to initialization, and
for properties that have been explicitly <span
class="function">unset. For all other properties true will
be returned.
错误/异常
Throws a ReflectionException if the property is inaccessible. You can make a protected or private property accessible using <span class="methodname">ReflectionProperty::setAccessible.
范例
示例 #1 <span class="methodname">ReflectionProperty::isInitialized example
<?php
class User
{
public string $name;
}
$rp = new ReflectionProperty('User', 'name');
$user = new User;
var_dump($rp->isInitialized($user));
$user->name = 'Nikita';
var_dump($rp->isInitialized($user));
?>
以上例程会输出:
bool(false)
bool(true)
参见
- ReflectionProperty::hasType
ReflectionProperty::isPrivate
Checks if property is private
说明
public bool ReflectionProperty::isPrivate ( <span class="methodparam">void )
Checks whether the property is private.
参数
此函数没有参数。
返回值
true if the property is private, false otherwise.
参见
- ReflectionProperty::isPublic
- ReflectionProperty::isProtected
- ReflectionProperty::isStatic
ReflectionProperty::isProtected
Checks if property is protected
说明
public bool ReflectionProperty::isProtected ( <span class="methodparam">void )
Checks whether the property is protected.
参数
此函数没有参数。
返回值
true if the property is protected, false otherwise.
参见
- ReflectionProperty::isPublic
- ReflectionProperty::isPrivate
- ReflectionProperty::isStatic
ReflectionProperty::isPublic
Checks if property is public
说明
public bool ReflectionProperty::isPublic ( <span class="methodparam">void )
Checks whether the property is public.
参数
此函数没有参数。
返回值
true if the property is public, false otherwise.
参见
- ReflectionProperty::isProtected
- ReflectionProperty::isPrivate
- ReflectionProperty::isStatic
ReflectionProperty::isStatic
Checks if property is static
说明
public bool ReflectionProperty::isStatic ( <span class="methodparam">void )
Checks whether the property is static.
参数
此函数没有参数。
返回值
true if the property is static, false otherwise.
参见
- ReflectionProperty::isPublic
- ReflectionProperty::isProtected
- ReflectionProperty::isPrivate
ReflectionProperty::setAccessible
Set property accessibility
说明
public void
ReflectionProperty::setAccessible (
bool
$accessible )
Sets a property to be accessible. For example, it may allow protected and private properties to be accessed.
参数
accessible
true to allow accessibility, or false.
返回值
没有返回值。
参见
- ReflectionProperty::isPrivate
- ReflectionProperty::isProtected
ReflectionProperty::setValue
Set property value
说明
public void
ReflectionProperty::setValue ( <span
class="methodparam">object $object ,
mixed
$value )
public void
ReflectionProperty::setValue ( <span
class="methodparam">mixed $value )
Sets (changes) the property's value.
参数
object
If the property is non-static an object must be provided to change the
property on. If the property is static this parameter is left out and
only value needs to be provided.
value
The new value.
返回值
没有返回值。
错误/异常
Throws a ReflectionException if the property is inaccessible. You can make a protected or private property accessible using <span class="methodname">ReflectionProperty::setAccessible.
范例
示例 #1 ReflectionProperty::setValue example
<?php
class Foo {
public static $staticProperty;
public $property;
protected $privateProperty;
}
$reflectionClass = new ReflectionClass('Foo');
$reflectionClass->getProperty('staticProperty')->setValue('foo');
var_dump(Foo::$staticProperty);
$foo = new Foo;
$reflectionClass->getProperty('property')->setValue($foo, 'bar');
var_dump($foo->property);
$reflectionProperty = $reflectionClass->getProperty('privateProperty');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($foo, 'foobar');
var_dump($reflectionProperty->getValue($foo));
?>
以上例程会输出:
string(3) "foo"
string(3) "bar"
string(6) "foobar"
参见
- ReflectionProperty::getValue
- ReflectionProperty::setAccessible
- <span class="methodname">ReflectionClass::setStaticPropertyValue
ReflectionProperty::__toString
To string
说明
public string ReflectionProperty::__toString ( <span class="methodparam">void )
To string.
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
参见
简介
ReflectionType 类用于获取函数、类方法的参数或者返回值的类型。
类摘要
ReflectionType
class ReflectionType {
/* 方法 */
public bool allowsNull ( <span class="methodparam">void )
public string __toString ( <span class="methodparam">void )
}
ReflectionType::allowsNull
Checks if null is allowed
说明
public bool ReflectionType::allowsNull ( <span class="methodparam">void )
Checks whether the parameter allows null.
参数
此函数没有参数。
返回值
true if null is allowed, otherwise false
范例
示例 #1 ReflectionType::allowsNull example
<?php
function someFunction(string $param, StdClass $param2 = null) {}
$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();
var_dump($reflectionParams[0]->getType()->allowsNull());
var_dump($reflectionParams[1]->getType()->allowsNull());
以上例程会输出:
bool(false)
bool(true)
参见
- ReflectionNamedType::isBuiltin
- ReflectionType::__toString
- ReflectionParameter::getType
ReflectionType::__toString
To string
Warning
本函数已自 PHP 7.1.0 起废弃。强烈建议不要使用本函数。
说明
public string ReflectionType::__toString ( <span class="methodparam">void )
Gets the parameter type name.
参数
此函数没有参数。
返回值
Returns the type of the parameter.
范例
示例 #1 ReflectionType::__toString example
<?php
function someFunction(string $param) {}
$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParam = $reflectionFunc->getParameters()[0];
echo $reflectionParam->getType();
以上例程的输出类似于:
string
更新日志
| 版本 | 说明 |
|---|---|
| 7.1.0 | ReflectionType::__toString has been deprecated. |
参见
- ReflectionNamedType::getName
- ReflectionNamedType::isBuiltin
- ReflectionType::allowsNull
- ReflectionUnionType::getTypes
- ReflectionParameter::getType
简介
<span class="classname">ReflectionGenerator类用于获取生成器的信息。
类摘要
ReflectionGenerator
class ReflectionGenerator {
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">Generator
$generator )
public string getExecutingFile ( <span class="methodparam">void )
public Generator getExecutingGenerator ( <span class="methodparam">void )
public int <span class="methodname">getExecutingLine ( <span class="methodparam">void )
public <span class="type">ReflectionFunctionAbstract <span class="methodname">getFunction ( <span class="methodparam">void )
public object getThis ( <span class="methodparam">void )
public array
getTrace ([ <span
class="methodparam">int $options<span
class="initializer"> = DEBUG_BACKTRACE_PROVIDE_OBJECT
] )
}
ReflectionGenerator::__construct
Constructs a ReflectionGenerator object
说明
public <span
class="methodname">ReflectionGenerator::__construct ( <span
class="methodparam">Generator
$generator )
Constructs a ReflectionGenerator object.
参数
generator
A generator object.
返回值
没有返回值。
范例
示例 #1 <span class="methodname">ReflectionGenerator::__construct example
<?php
function gen()
{
yield 1;
}
$gen = gen();
$reflectionGen = new ReflectionGenerator($gen);
echo <<< output
{$reflectionGen->getFunction()->name}
Line: {$reflectionGen->getExecutingLine()}
File: {$reflectionGen->getExecutingFile()}
output;
以上例程的输出类似于:
gen
Line: 5
File: /path/to/file/example.php
参见
- ReflectionGenerator::getFunction
- <span class="methodname">ReflectionGenerator::getExecutingLine
- <span class="methodname">ReflectionGenerator::getExecutingFile
ReflectionGenerator::getExecutingFile
Gets the file name of the currently executing generator
说明
public string ReflectionGenerator::getExecutingFile ( void )
Get the full path and file name of the currently executing generator.
参数
此函数没有参数。
返回值
Returns the full path and file name of the currently executing generator.
范例
示例 #1 <span class="methodname">ReflectionGenerator::getExecutingFile example
<?php
class GenExample
{
public function gen()
{
yield 1;
}
}
$gen = (new GenExample)->gen();
$reflectionGen = new ReflectionGenerator($gen);
echo "File: {$reflectionGen->getExecutingFile()}";
以上例程的输出类似于:
File: /path/to/file/example.php
参见
- <span class="methodname">ReflectionGenerator::getExecutingLine
- <span class="methodname">ReflectionGenerator::getExecutingGenerator
ReflectionGenerator::getExecutingGenerator
Gets the executing Generator object
说明
public Generator <span class="methodname">ReflectionGenerator::getExecutingGenerator ( void )
Get the executing Generator object
参数
此函数没有参数。
返回值
Returns the currently executing Generator object.
范例
示例 #1 <span class="methodname">ReflectionGenerator::getExecutingGenerator example
<?php
class GenExample
{
public function gen()
{
yield 1;
}
}
$gen = (new GenExample)->gen();
$reflectionGen = new ReflectionGenerator($gen);
$gen2 = $reflectionGen->getExecutingGenerator();
var_dump($gen2 === $gen);
var_dump($gen2->current());
以上例程的输出类似于:
bool(true)
int(1);
参见
- <span class="methodname">ReflectionGenerator::getExecutingLine
- <span class="methodname">ReflectionGenerator::getExecutingFile
ReflectionGenerator::getExecutingLine
Gets the currently executing line of the generator
说明
public int <span class="methodname">ReflectionGenerator::getExecutingLine ( <span class="methodparam">void )
Get the currently executing line number of the generator.
参数
此函数没有参数。
返回值
Returns the line number of the currently executing statement in the generator.
范例
示例 #1 <span class="methodname">ReflectionGenerator::getExecutingLine example
<?php
class GenExample
{
public function gen()
{
yield 1;
}
}
$gen = (new GenExample)->gen();
$reflectionGen = new ReflectionGenerator($gen);
echo "Line: {$reflectionGen->getExecutingLine()}";
以上例程的输出类似于:
Line: 7
参见
- <span class="methodname">ReflectionGenerator::getExecutingGenerator
- <span class="methodname">ReflectionGenerator::getExecutingFile
ReflectionGenerator::getFunction
Gets the function name of the generator
说明
public <span class="type">ReflectionFunctionAbstract <span class="methodname">ReflectionGenerator::getFunction ( <span class="methodparam">void )
Enables the function name of the generator to be obtained by returning a class derived from <span class="classname">ReflectionFunctionAbstract.
参数
此函数没有参数。
返回值
Returns a ReflectionFunctionAbstract class. This will be ReflectionFunction for functions, or ReflectionMethod for methods.
范例
示例 #1 <span class="methodname">ReflectionGenerator::getFunction example
<?php
function gen()
{
yield 1;
}
$gen = gen();
$reflectionGen = new ReflectionGenerator($gen);
var_dump($reflectionGen->getFunction());
以上例程的输出类似于:
object(ReflectionFunction)#3 (1) {
["name"]=>
string(3) "gen"
}
参见
- ReflectionGenerator::getThis
- ReflectionGenerator::getTrace
ReflectionGenerator::getThis
Gets the $this value of the generator
说明
public object ReflectionGenerator::getThis ( <span class="methodparam">void )
Get the $this value that the generator has access to.
参数
此函数没有参数。
返回值
Returns the $this value, or null if the generator was not
created in a class context.
范例
示例 #1 ReflectionGenerator::getThis example
<?php
class GenExample
{
public function gen()
{
yield 1;
}
}
$gen = (new GenExample)->gen();
$reflectionGen = new ReflectionGenerator($gen);
var_dump($reflectionGen->getThis());
以上例程的输出类似于:
object(GenExample)#3 (0) {
}
参见
- ReflectionGenerator::getFunction
- ReflectionGenerator::getTrace
ReflectionGenerator::getTrace
Gets the trace of the executing generator
说明
public array
ReflectionGenerator::getTrace ([ <span
class="methodparam">int $options<span
class="initializer"> = DEBUG_BACKTRACE_PROVIDE_OBJECT
] )
Get the trace of the currently executing generator.
参数
options
The value of options can be any of the following flags.
| Option | Description |
|---|---|
DEBUG_BACKTRACE_PROVIDE_OBJECT |
Default. |
DEBUG_BACKTRACE_IGNORE_ARGS |
Don't include the argument information for functions in the stack trace. |
返回值
Returns the trace of the currently executing generator.
范例
示例 #1 ReflectionGenerator::getTrace example
<?php
function foo() {
yield 1;
}
function bar()
{
yield from foo();
}
function baz()
{
yield from bar();
}
$gen = baz();
$gen->valid(); // start the generator
var_dump((new ReflectionGenerator($gen))->getTrace());
以上例程的输出类似于:
array(2) {
[0]=>
array(4) {
["file"]=>
string(18) "example.php"
["line"]=>
int(8)
["function"]=>
string(3) "foo"
["args"]=>
array(0) {
}
}
[1]=>
array(4) {
["file"]=>
string(18) "example.php"
["line"]=>
int(12)
["function"]=>
string(3) "bar"
["args"]=>
array(0) {
}
}
}
参见
- ReflectionGenerator::getFunction
- ReflectionGenerator::getThis
简介
Reflector 是一个接口,被所有可导出的反射类所实现(implement)。
类摘要
Reflector
class Reflector {
/* 方法 */
public <span class="modifier">static string <span class="methodname">export ( void )
public string __toString ( <span class="methodparam">void )
}
Reflector::export
Exports
说明
public <span class="modifier">static string <span class="methodname">Reflector::export ( <span class="methodparam">void )
输出。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
参见
- Reflection::__toString
Reflector::__toString
转化成字符串
说明
public string Reflector::__toString ( <span class="methodparam">void )
转化成字符串。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
参见
- ReflectionProperty::export
- __toString()
简介
ReflectionException 类。
类摘要
ReflectionException
class ReflectionException <span class="ooclass"> extends Exception {
/* 属性 */
protected string
$message ;
protected int
$code ;
protected string
$file ;
protected int
$line ;
/* 继承的方法 */
final public string <span class="methodname">Exception::getMessage ( <span class="methodparam">void )
final public Throwable <span class="methodname">Exception::getPrevious ( <span class="methodparam">void )
final public mixed <span class="methodname">Exception::getCode ( <span class="methodparam">void )
final public string <span class="methodname">Exception::getFile ( <span class="methodparam">void )
final public int <span class="methodname">Exception::getLine ( <span class="methodparam">void )
final public array <span class="methodname">Exception::getTrace ( <span class="methodparam">void )
final public string <span class="methodname">Exception::getTraceAsString ( <span class="methodparam">void )
public string Exception::__toString ( <span class="methodparam">void )
final <span class="modifier">private void <span class="methodname">Exception::__clone ( <span class="methodparam">void )
}