# 反射

# 简介

PHP 具有完整的反射 API，增加了内省类、接口、函数、方法和扩展的能力。 此外，反射 API 提供了方法来取出函数、类和方法中的文档注释。

请注意部分内部 API 丢失了反射扩展工作所需的代码。 例如，一个内置的 PHP 类可能丢失了反射属性的数据。这些少数的情况被认为是错误，不过， 正因为如此，它们应该被发现和修复。

- 示例
- 扩展
- Reflection — Reflection 类
  - Reflection::export — 导出
  - Reflection::getModifierNames — 获取修饰符的名称
- ReflectionClass — ReflectionClass 类
  - ReflectionClass::__construct — 初始化 ReflectionClass 类
  - ReflectionClass::export — 导出类
  - ReflectionClass::getAttributes — 获取所有属性
  - 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::getLazyInitializer — Gets lazy initializer
  - 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::initializeLazyObject — Forces initialization of a lazy object
  - ReflectionClass::inNamespace — 检查是否位于命名空间中
  - ReflectionClass::isAbstract — 检查类是否是抽象类（abstract）
  - ReflectionClass::isAnonymous — 检查类是否是匿名类
  - ReflectionClass::isCloneable — 返回了一个类是否可复制
  - ReflectionClass::isEnum — Returns whether this is an enum
  - ReflectionClass::isFinal — 检查类是否声明为 final
  - ReflectionClass::isInstance — 检查类的实例
  - ReflectionClass::isInstantiable — 检查类是否可实例化
  - ReflectionClass::isInterface — 检查类是否是接口（interface）
  - ReflectionClass::isInternal — 检查类是否由扩展或核心在内部定义
  - ReflectionClass::isIterable — Check whether this class is iterable
  - ReflectionClass::isIterateable — 别名 ReflectionClass::isIterable
  - ReflectionClass::isReadOnly — Checks if class is readonly
  - ReflectionClass::isSubclassOf — 检查是否为子类
  - ReflectionClass::isTrait — 返回了是否是 trait
  - ReflectionClass::isUninitializedLazyObject — Checks if an object is lazy and uninitialized
  - ReflectionClass::isUserDefined — 检查是否由用户定义的
  - ReflectionClass::markLazyObjectAsInitialized — Marks a lazy object as initialized without calling the initializer or factory
  - ReflectionClass::newInstance — 从指定的参数创建新类实例
  - ReflectionClass::newInstanceArgs — 从给出的参数创建一个新的类实例
  - ReflectionClass::newInstanceWithoutConstructor — 创建新的类实例而不调用它的构造函数
  - ReflectionClass::newLazyGhost — Creates a new lazy ghost instance
  - ReflectionClass::newLazyProxy — Creates a new lazy proxy instance
  - ReflectionClass::resetAsLazyGhost — Resets an object and marks it as lazy
  - ReflectionClass::resetAsLazyProxy — Resets an object and marks it as lazy
  - ReflectionClass::setStaticPropertyValue — 设置 public static 属性的值
  - ReflectionClass::__toString — 返回 ReflectionClass 对象字符串的表示形式
- ReflectionClassConstant — The ReflectionClassConstant class
  - ReflectionClassConstant::__construct — Constructs a ReflectionClassConstant
  - ReflectionClassConstant::export — Export
  - ReflectionClassConstant::getAttributes — Gets Attributes
  - 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::getType — Gets a class constant's type
  - ReflectionClassConstant::getValue — Gets value
  - ReflectionClassConstant::hasType — Checks if class constant has a type
  - ReflectionClassConstant::isDeprecated — Checks if deprecated
  - ReflectionClassConstant::isEnumCase — Checks if class constant is an Enum case
  - ReflectionClassConstant::isFinal — Checks if class constant is final
  - 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
- ReflectionConstant — The ReflectionConstant class
  - ReflectionConstant::__construct — Constructs a ReflectionConstant
  - ReflectionConstant::getExtension — Gets ReflectionExtension of the defining extension
  - ReflectionConstant::getExtensionName — Gets name of the defining extension
  - ReflectionConstant::getFileName — Gets name of the defining file
  - ReflectionConstant::getName — Gets name
  - ReflectionConstant::getNamespaceName — Gets namespace name
  - ReflectionConstant::getShortName — Gets short name
  - ReflectionConstant::getValue — Gets value
  - ReflectionConstant::isDeprecated — Checks if deprecated
  - ReflectionConstant::__toString — Returns string representation
- ReflectionEnum — ReflectionEnum 类
  - ReflectionEnum::__construct — 实例化 ReflectionEnum 对象
  - ReflectionEnum::getBackingType — 获取枚举回退的类型
  - ReflectionEnum::getCase — 返回指定的枚举条目
  - ReflectionEnum::getCases — 返回枚举中的所有条目的清单
  - ReflectionEnum::hasCase — 在枚举上检测条目
  - ReflectionEnum::isBacked — 检测 Enum 是否为回退（Backed）Enum
- ReflectionEnumUnitCase — ReflectionEnumUnitCase 类
  - ReflectionEnumUnitCase::__construct — Instantiates a ReflectionEnumUnitCase object
  - ReflectionEnumUnitCase::getEnum — 获取该枚举条目的反射
  - ReflectionEnumUnitCase::getValue — 获取反射对象描述的枚举条目对象
- ReflectionEnumBackedCase — ReflectionEnumBackedCase 类
  - ReflectionEnumBackedCase::__construct — Instantiates a ReflectionEnumBackedCase object
  - ReflectionEnumBackedCase::getBackingValue — 获取枚举条目回退的标量值
- ReflectionZendExtension — ReflectionZendExtension 类
  - ReflectionZendExtension::__clone — Clone handler
  - ReflectionZendExtension::__construct — Constructs a ReflectionZendExtension object
  - 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 — 克隆
  - ReflectionExtension::__construct — 构造 ReflectionExtension
  - ReflectionExtension::export — Export
  - ReflectionExtension::getClasses — 获取类列表
  - ReflectionExtension::getClassNames — 获取类名列表
  - ReflectionExtension::getConstants — 获取常量
  - ReflectionExtension::getDependencies — 获取依赖
  - ReflectionExtension::getFunctions — 获取扩展中的函数
  - ReflectionExtension::getINIEntries — 获取 ini 配置
  - ReflectionExtension::getName — 获取扩展名称
  - ReflectionExtension::getVersion — 获取扩展版本
  - ReflectionExtension::info — 输出扩展信息
  - ReflectionExtension::isPersistent — 返回扩展是否持久化的
  - ReflectionExtension::isTemporary — 返回扩展是否是临时载入
  - ReflectionExtension::__toString — 生成字符串
- 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::isAnonymous — Checks if a function is anonymous
  - ReflectionFunction::isDisabled — Checks if function is disabled
  - ReflectionFunction::__toString — Returns the string representation of the ReflectionFunction object
- ReflectionFunctionAbstract — ReflectionFunctionAbstract 类
  - ReflectionFunctionAbstract::__clone — 复制函数
  - ReflectionFunctionAbstract::getAttributes — Gets Attributes
  - ReflectionFunctionAbstract::getClosureCalledClass — Returns the class corresponding to static:: inside a closure
  - ReflectionFunctionAbstract::getClosureScopeClass — Returns the class corresponding to the scope inside a closure
  - ReflectionFunctionAbstract::getClosureThis — 返回闭包内与 $this 对应的对象
  - ReflectionFunctionAbstract::getClosureUsedVariables — Returns an array of the used variables in the Closure
  - 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::getTentativeReturnType — Returns the tentative return type associated with the function
  - ReflectionFunctionAbstract::hasReturnType — Checks if the function has a specified return type
  - ReflectionFunctionAbstract::hasTentativeReturnType — Returns whether the function has a tentative return type
  - ReflectionFunctionAbstract::inNamespace — 检查是否处于命名空间
  - ReflectionFunctionAbstract::isClosure — 检查是否是匿名函数
  - ReflectionFunctionAbstract::isDeprecated — 检查是否已经弃用
  - ReflectionFunctionAbstract::isGenerator — 判断函数是否是一个生成器函数
  - ReflectionFunctionAbstract::isInternal — 判断函数是否是内置函数
  - ReflectionFunctionAbstract::isStatic — 判断函数是否为 static
  - ReflectionFunctionAbstract::isUserDefined — 检查是否是用户定义
  - ReflectionFunctionAbstract::isVariadic — Checks if the function is variadic
  - ReflectionFunctionAbstract::returnsReference — 检查是否返回引用
  - ReflectionFunctionAbstract::__toString — 返回表示 ReflectionFunctionAbstract 对象的字符串
- ReflectionMethod — ReflectionMethod 类
  - ReflectionMethod::__construct — 构造 ReflectionMethod
  - ReflectionMethod::createFromMethodName — Creates a new ReflectionMethod
  - ReflectionMethod::export — 导出 reflection 方法
  - ReflectionMethod::getClosure — 返回动态建立的方法调用接口（译者注：可以使用这个返回值直接调用非公开方法）
  - ReflectionMethod::getDeclaringClass — 获取被反射的方法所在类的反射实例
  - ReflectionMethod::getModifiers — 获取方法的修饰符
  - ReflectionMethod::getPrototype — 返回方法原型 (如果存在)
  - ReflectionMethod::hasPrototype — Returns whether a method has a prototype
  - ReflectionMethod::invoke — Invoke
  - ReflectionMethod::invokeArgs — 带参数执行
  - ReflectionMethod::isAbstract — 判断方法是否是抽象方法
  - ReflectionMethod::isConstructor — 判断方法是否是构造方法
  - ReflectionMethod::isDestructor — 判断方法是否是析构方法
  - ReflectionMethod::isFinal — 判断方法是否定义 final
  - ReflectionMethod::isPrivate — 判断方法是否是私有
  - ReflectionMethod::isProtected — 判断方法是否是 protected
  - ReflectionMethod::isPublic — 判断方法是否是 public
  - ReflectionMethod::setAccessible — 设置方法是否可访问
  - ReflectionMethod::__toString — 返回反射方法对象的字符串表达
- ReflectionNamedType — ReflectionNamedType 类
  - ReflectionNamedType::getName — 以字符串形式获取类型的名称
  - ReflectionNamedType::isBuiltin — 检查它是否是内置类型
- 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::getAttributes — Gets Attributes
  - ReflectionParameter::getClass — 获取参数的 ReflectionClass 对象或为 null
  - 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::isPromoted — Checks if a parameter is promoted to a property
  - 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::getAttributes — Gets Attributes
  - ReflectionProperty::getDeclaringClass — Gets declaring class
  - ReflectionProperty::getDefaultValue — Returns the default value declared for a property
  - ReflectionProperty::getDocComment — Gets the property doc comment
  - ReflectionProperty::getHook — Returns a reflection object for a specified hook
  - ReflectionProperty::getHooks — Returns an array of all hooks on this property
  - ReflectionProperty::getModifiers — Gets the property modifiers
  - ReflectionProperty::getName — Gets property name
  - ReflectionProperty::getRawValue — Returns the value of a property, bypassing a get hook if defined
  - ReflectionProperty::getSettableType — Returns the parameter type of a setter hook
  - ReflectionProperty::getType — Gets a property's type
  - ReflectionProperty::getValue — Gets value
  - ReflectionProperty::hasDefaultValue — Checks if property has a default value declared
  - ReflectionProperty::hasHook — Returns whether the property has a given hook defined
  - ReflectionProperty::hasHooks — Returns whether the property has any hooks defined
  - ReflectionProperty::hasType — Checks if property has a type
  - ReflectionProperty::isAbstract — Determines if a property is abstract
  - ReflectionProperty::isDefault — Checks if property is a default property
  - ReflectionProperty::isDynamic — Checks if property is a dynamic property
  - ReflectionProperty::isFinal — Determines if this property is final or not
  - ReflectionProperty::isInitialized — Checks whether a property is initialized
  - ReflectionProperty::isLazy — Checks whether a property is lazy
  - ReflectionProperty::isPrivate — Checks if property is private
  - ReflectionProperty::isPrivateSet — Checks if property is private for writing
  - ReflectionProperty::isPromoted — Checks if property is promoted
  - ReflectionProperty::isProtected — Checks if property is protected
  - ReflectionProperty::isProtectedSet — Checks whether the property is protected for writing
  - ReflectionProperty::isPublic — Checks if property is public
  - ReflectionProperty::isReadOnly — 检查属性是否为只读
  - ReflectionProperty::isStatic — Checks if property is static
  - ReflectionProperty::isVirtual — Determines if a property is virtual
  - ReflectionProperty::setAccessible — Set property accessibility
  - ReflectionProperty::setRawValue — Sets the value of a property, bypassing a set hook if defined
  - ReflectionProperty::setRawValueWithoutLazyInitialization — Set raw property value without triggering lazy initialization
  - ReflectionProperty::setValue — Set property value
  - ReflectionProperty::skipLazyInitialization — Marks property as non-lazy
  - ReflectionProperty::__toString — To string
- ReflectionType — ReflectionType 类
  - ReflectionType::allowsNull — Checks if null is allowed
  - ReflectionType::__toString — To string
- ReflectionUnionType — ReflectionUnionType 类
  - ReflectionUnionType::getTypes — 返回联合类型中包含的类型
- ReflectionGenerator — 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
  - ReflectionGenerator::isClosed — Checks if execution finished
- ReflectionFiber — ReflectionFiber 类
  - ReflectionFiber::__construct — Constructs a ReflectionFiber object
  - ReflectionFiber::getCallable — Gets the callable used to create the Fiber
  - ReflectionFiber::getExecutingFile — Get the file name of the current execution point
  - ReflectionFiber::getExecutingLine — Get the line number of the current execution point
  - ReflectionFiber::getFiber — Get the reflected Fiber instance
  - ReflectionFiber::getTrace — Get the backtrace of the current execution point
- ReflectionIntersectionType — ReflectionIntersectionType 类
  - ReflectionIntersectionType::getTypes — 返回包含在交集类型中的类型
- ReflectionReference — ReflectionReference 类
  - ReflectionReference::__construct — 私有构造函数以禁用直接实例化
  - ReflectionReference::fromArrayElement — 从数组元素创建一个 ReflectionReference
  - ReflectionReference::getId — 获取引用的唯一 ID
- ReflectionAttribute — ReflectionAttribute 类
  - ReflectionAttribute::__construct — 禁止直接实例化的私有构造函数
  - ReflectionAttribute::getArguments — 获取传递给属性的参数
  - ReflectionAttribute::getName — 获取属性名称
  - ReflectionAttribute::getTarget — 返回属性的目标位掩码
  - ReflectionAttribute::isRepeated — 返回该名称的属性是否已重复出现在代码元素上
  - ReflectionAttribute::newInstance — 实例化由 ReflectionAttribute 类和参数表示的属性类
- Reflector — Reflector 接口
  - Reflector::export — Exports
- ReflectionException — ReflectionException 类
- PropertyHookType — PropertyHookType 枚举

`↑` and `↓` to navigate • `Enter` to select • `Esc` to close • `/` to open