リフレクション

目次

Reflection クラス

はじめに

リフレクションクラスです。

クラス概要

Reflection
/* メソッド */
public static string export(Reflector $reflector, bool $return = false)
public static array getModifierNames(int $modifiers)

ReflectionClass クラス

はじめに

ReflectionClass クラスは クラスについての情報を報告します。

クラス概要

ReflectionClass
implements Reflector
/* 定数 */
public const int ReflectionClass::IS_IMPLICIT_ABSTRACT;
public const int ReflectionClass::IS_EXPLICIT_ABSTRACT;
public const int ReflectionClass::IS_FINAL;
public const int ReflectionClass::IS_READONLY;
/* プロパティ */
public string $name;
/* メソッド */
public __construct(objectstring $objectOrClass)
public static string export(mixed $argument, bool $return = false)
public array getAttributes(stringnull $name = null, int $flags = 0)
public mixed getConstant(string $name)
public array getConstants(intnull $filter = null)
public ReflectionMethodnull getConstructor()
public array getDefaultProperties()
public stringfalse getDocComment()
public intfalse getEndLine()
public ReflectionExtensionnull getExtension()
public stringfalse getExtensionName()
public stringfalse getFileName()
public array getInterfaceNames()
public array getInterfaces()
public ReflectionMethod getMethod(string $name)
public array getMethods(intnull $filter = null)
public int getModifiers()
public string getName()
public string getNamespaceName()
public ReflectionClassfalse getParentClass()
public array getProperties(intnull $filter = null)
public ReflectionProperty getProperty(string $name)
public ReflectionClassConstantfalse getReflectionConstant(string $name)
public array getReflectionConstants(intnull $filter = null)
public string getShortName()
public intfalse getStartLine()
public array getStaticProperties()
public mixed getStaticPropertyValue(string $name, mixed &$def_value = ?)
public array getTraitAliases()
public array getTraitNames()
public array getTraits()
public bool hasConstant(string $name)
public bool hasMethod(string $name)
public bool hasProperty(string $name)
public bool implementsInterface(ReflectionClassstring $interface)
public bool inNamespace()
public bool isAbstract()
public bool isAnonymous()
public bool isCloneable()
public bool isEnum()
public bool isFinal()
public bool isInstance(object $object)
public bool isInstantiable()
public bool isInterface()
public bool isInternal()
public bool isIterable()
public bool isReadOnly()
public bool isSubclassOf(ReflectionClassstring $class)
public bool isTrait()
public bool isUserDefined()
public object newInstance(mixed ...$args)
public objectnull newInstanceArgs(array $args = [])
public object newInstanceWithoutConstructor()
public void setStaticPropertyValue(string $name, mixed $value)
public string __toString()

プロパティ

name

クラス名。読み込み専用で、書き込もうとすると ReflectionException をスローします。

定義済み定数

ReflectionClass の修飾子

ReflectionClass::IS_IMPLICIT_ABSTRACT

抽象メソッドを持っているので abstract クラスであることを示します。

ReflectionClass::IS_EXPLICIT_ABSTRACT

その定義から abstract クラスであることを示します。

ReflectionClass::IS_FINAL

final クラスであることを示します。

ReflectionClass::IS_READONLY

readonly クラスであることを示します。

変更履歴

バージョン 説明
8.0.0 ReflectionClass::export は、削除されました。

ReflectionClassConstant クラス

はじめに

ReflectionClassConstant クラスは、クラス定数に関する情報を報告します。

クラス概要

ReflectionClassConstant
implements Reflector
/* 定数 */
public const int ReflectionClassConstant::IS_PUBLIC;
public const int ReflectionClassConstant::IS_PROTECTED;
public const int ReflectionClassConstant::IS_PRIVATE;
public const int ReflectionClassConstant::IS_FINAL;
/* プロパティ */
public string $name;
public string $class;
/* メソッド */
public __construct(objectstring $class, string $constant)
public static string export(mixed $class, string $name, bool $return = ?)
public array getAttributes(stringnull $name = null, int $flags = 0)
public ReflectionClass getDeclaringClass()
public stringfalse getDocComment()
public int getModifiers()
public string getName()
public mixed getValue()
public bool isEnumCase()
public bool isFinal()
public bool isPrivate()
public bool isProtected()
public bool isPublic()
public string __toString()

プロパティ

name

クラス定数の名前。読み取り専用です。 書き込もうとすると ReflectionException がスローされます。

class

クラス定数が定義されたクラス名。読み取り専用です。 書き込もうとすると ReflectionException がスローされます。

定義済み定数

ReflectionClassConstant の修飾子

ReflectionClassConstant::IS_PUBLIC

アクセス権が public であることを示します。 PHP 7.4.0 より前のバージョンでは、この値は 256 でした。

ReflectionClassConstant::IS_PROTECTED

アクセス権が protected であることを示します。 PHP 7.4.0 より前のバージョンでは、この値は 512 でした。

ReflectionClassConstant::IS_PRIVATE

アクセス権が private であることを示します。 PHP 7.4.0 より前のバージョンでは、この値は 1024 でした。

ReflectionClassConstant::IS_FINAL

定数が final であることを示します。 PHP 8.1.0 以降で利用可能です。

注意:

これらの定数の値は、PHP のバージョンが異なると変更される可能性があります。 これらの値を直接用いず、常に定数を使うことを推奨します。

変更履歴

バージョン 説明
8.0.0 ReflectionClassConstant::export は、削除されました。

ReflectionEnum クラス

はじめに

ReflectionEnum クラスは、 列挙型に関する情報を報告します。

クラス概要

ReflectionEnum
extends ReflectionClass
/* 継承した定数 */
public const int ReflectionClass::IS_IMPLICIT_ABSTRACT;
public const int ReflectionClass::IS_EXPLICIT_ABSTRACT;
public const int ReflectionClass::IS_FINAL;
public const int ReflectionClass::IS_READONLY;
/* 継承したプロパティ */
public string $name;
/* メソッド */
public ReflectionEnum::__construct(objectstring $objectOrClass)
public ReflectionNamedTypenull ReflectionEnum::getBackingType()
public ReflectionEnumUnitCase ReflectionEnum::getCase(string $name)
public array ReflectionEnum::getCases()
public bool ReflectionEnum::hasCase(string $name)
public bool ReflectionEnum::isBacked()
/* 継承したメソッド */
public static string export(mixed $argument, bool $return = false)
public array getAttributes(stringnull $name = null, int $flags = 0)
public mixed getConstant(string $name)
public array getConstants(intnull $filter = null)
public ReflectionMethodnull getConstructor()
public array getDefaultProperties()
public stringfalse getDocComment()
public intfalse getEndLine()
public ReflectionExtensionnull getExtension()
public stringfalse getExtensionName()
public stringfalse getFileName()
public array getInterfaceNames()
public array getInterfaces()
public ReflectionMethod getMethod(string $name)
public array getMethods(intnull $filter = null)
public int getModifiers()
public string getName()
public string getNamespaceName()
public ReflectionClassfalse getParentClass()
public array getProperties(intnull $filter = null)
public ReflectionProperty getProperty(string $name)
public ReflectionClassConstantfalse getReflectionConstant(string $name)
public array getReflectionConstants(intnull $filter = null)
public string getShortName()
public intfalse getStartLine()
public array getStaticProperties()
public mixed getStaticPropertyValue(string $name, mixed &$def_value = ?)
public array getTraitAliases()
public array getTraitNames()
public array getTraits()
public bool hasConstant(string $name)
public bool hasMethod(string $name)
public bool hasProperty(string $name)
public bool implementsInterface(ReflectionClassstring $interface)
public bool inNamespace()
public bool isAbstract()
public bool isAnonymous()
public bool isCloneable()
public bool isEnum()
public bool isFinal()
public bool isInstance(object $object)
public bool isInstantiable()
public bool isInterface()
public bool isInternal()
public bool isIterable()
public bool isReadOnly()
public bool isSubclassOf(ReflectionClassstring $class)
public bool isTrait()
public bool isUserDefined()
public object newInstance(mixed ...$args)
public objectnull newInstanceArgs(array $args = [])
public object newInstanceWithoutConstructor()
public void setStaticPropertyValue(string $name, mixed $value)
public string __toString()

ReflectionEnumUnitCase クラス

はじめに

ReflectionEnumUnitCase クラスは、 列挙型 の case に関する情報を報告します。 これは、スカラー型の情報を持っていません。

クラス概要

ReflectionEnumUnitCase
extends ReflectionClassConstant
/* 継承した定数 */
public const int ReflectionClassConstant::IS_PUBLIC;
public const int ReflectionClassConstant::IS_PROTECTED;
public const int ReflectionClassConstant::IS_PRIVATE;
public const int ReflectionClassConstant::IS_FINAL;
/* 継承したプロパティ */
public string $name;
public string $class;
/* メソッド */
public ReflectionEnumUnitCase::__construct(objectstring $class, string $constant)
public ReflectionEnum ReflectionEnumUnitCase::getEnum()
public UnitEnum ReflectionEnumUnitCase::getValue()
/* 継承したメソッド */
public static string export(mixed $class, string $name, bool $return = ?)
public array getAttributes(stringnull $name = null, int $flags = 0)
public ReflectionClass getDeclaringClass()
public stringfalse getDocComment()
public int getModifiers()
public string getName()
public mixed getValue()
public bool isEnumCase()
public bool isFinal()
public bool isPrivate()
public bool isProtected()
public bool isPublic()
public string __toString()

参考

ReflectionEnumBackedCase クラス

はじめに

ReflectionEnumBackedCase クラスは、 Backed Enum の case に関する情報を報告します。 これは、スカラー型の情報を持っています。

クラス概要

ReflectionEnumBackedCase
extends ReflectionEnumUnitCase
/* 継承した定数 */
public const int ReflectionClassConstant::IS_PUBLIC;
public const int ReflectionClassConstant::IS_PROTECTED;
public const int ReflectionClassConstant::IS_PRIVATE;
public const int ReflectionClassConstant::IS_FINAL;
/* 継承したプロパティ */
public string $name;
public string $class;
/* メソッド */
public ReflectionEnumBackedCase::__construct(objectstring $class, string $constant)
public intstring ReflectionEnumBackedCase::getBackingValue()
/* 継承したメソッド */
public ReflectionEnum getEnum()
public UnitEnum getValue()
public static string ReflectionClassConstant::export(mixed $class, string $name, bool $return = ?)
public array ReflectionClassConstant::getAttributes(stringnull $name = null, int $flags = 0)
public ReflectionClass ReflectionClassConstant::getDeclaringClass()
public stringfalse ReflectionClassConstant::getDocComment()
public int ReflectionClassConstant::getModifiers()
public string ReflectionClassConstant::getName()
public mixed ReflectionClassConstant::getValue()
public bool ReflectionClassConstant::isEnumCase()
public bool ReflectionClassConstant::isFinal()
public bool ReflectionClassConstant::isPrivate()
public bool ReflectionClassConstant::isProtected()
public bool ReflectionClassConstant::isPublic()
public string ReflectionClassConstant::__toString()

参考

ReflectionZendExtension クラス

はじめに

クラス概要

ReflectionZendExtension
implements Reflector
/* プロパティ */
public string $name;
/* メソッド */
public __construct(string $name)
private void __clone()
public static string export(string $name, bool $return = ?)
public string getAuthor()
public string getCopyright()
public string getName()
public string getURL()
public string getVersion()
public string __toString()

プロパティ

name

拡張モジュール名。読み込み専用で、書き込もうとすると ReflectionException をスローします。

変更履歴

バージョン 説明
8.0.0 ReflectionZendExtension::export は、削除されました。

ReflectionExtension クラス

はじめに

ReflectionExtension クラスは 拡張モジュールについての情報を報告します。

クラス概要

ReflectionExtension
implements Reflector
/* プロパティ */
public string $name;
/* メソッド */
public __construct(string $name)
private void __clone()
public static string export(string $name, string $return = false)
public array getClasses()
public array getClassNames()
public array getConstants()
public array getDependencies()
public array getFunctions()
public array getINIEntries()
public string getName()
public stringnull getVersion()
public void info()
public bool isPersistent()
public bool isTemporary()
public string __toString()

プロパティ

name

拡張モジュールの名前。 ReflectionExtension::getName メソッドをコールするのと同じ。

変更履歴

バージョン 説明
8.0.0 ReflectionExtension::export は、削除されました。

ReflectionFunction クラス

はじめに

ReflectionFunction クラスは 関数についての情報を報告します。

クラス概要

ReflectionFunction
extends ReflectionFunctionAbstract
/* 定数 */
public const int ReflectionFunction::IS_DEPRECATED;
/* 継承したプロパティ */
public string $name;
/* メソッド */
public ReflectionFunction::__construct(Closurestring $function)
public static string ReflectionFunction::export(string $name, string $return = ?)
public Closure ReflectionFunction::getClosure()
public mixed ReflectionFunction::invoke(mixed ...$args)
public mixed ReflectionFunction::invokeArgs(array $args)
public bool ReflectionFunction::isAnonymous()
public bool ReflectionFunction::isDisabled()
public string ReflectionFunction::__toString()
/* 継承したメソッド */
private void __clone()
public array getAttributes(stringnull $name = null, int $flags = 0)
public ReflectionClassnull getClosureScopeClass()
public objectnull getClosureThis()
public array getClosureUsedVariables()
public stringfalse getDocComment()
public intfalse getEndLine()
public ReflectionExtensionnull getExtension()
public stringfalse getExtensionName()
public stringfalse getFileName()
public string getName()
public string getNamespaceName()
public int getNumberOfParameters()
public int getNumberOfRequiredParameters()
public array getParameters()
public ReflectionTypenull getReturnType()
public string getShortName()
public intfalse getStartLine()
public array getStaticVariables()
public ReflectionTypenull getTentativeReturnType()
public bool hasReturnType()
public bool hasTentativeReturnType()
public bool inNamespace()
public bool isClosure()
public bool isDeprecated()
public bool isGenerator()
public bool isInternal()
public bool isStatic()
public bool isUserDefined()
public bool isVariadic()
public bool returnsReference()
abstract public void __toString()

定義済み定数

ReflectionFunction の修飾子

ReflectionFunction::IS_DEPRECATED

非推奨の関数であることを示します。

変更履歴

バージョン 説明
8.0.0 ReflectionFunction::export は、削除されました。

ReflectionFunctionAbstract クラス

はじめに

ReflectionFunction の親クラスです。 詳細はこのクラスの説明を参照ください。

クラス概要

abstract ReflectionFunctionAbstract
implements Reflector
/* プロパティ */
public string $name;
/* メソッド */
private void __clone()
public array getAttributes(stringnull $name = null, int $flags = 0)
public ReflectionClassnull getClosureScopeClass()
public objectnull getClosureThis()
public array getClosureUsedVariables()
public stringfalse getDocComment()
public intfalse getEndLine()
public ReflectionExtensionnull getExtension()
public stringfalse getExtensionName()
public stringfalse getFileName()
public string getName()
public string getNamespaceName()
public int getNumberOfParameters()
public int getNumberOfRequiredParameters()
public array getParameters()
public ReflectionTypenull getReturnType()
public string getShortName()
public intfalse getStartLine()
public array getStaticVariables()
public ReflectionTypenull getTentativeReturnType()
public bool hasReturnType()
public bool hasTentativeReturnType()
public bool inNamespace()
public bool isClosure()
public bool isDeprecated()
public bool isGenerator()
public bool isInternal()
public bool isStatic()
public bool isUserDefined()
public bool isVariadic()
public bool returnsReference()
abstract public void __toString()

プロパティ

name

関数名。読み込み専用で、書き込もうとすると ReflectionException をスローします。

ReflectionMethod クラス

はじめに

ReflectionMethod クラスは メソッドについての情報を報告します。

クラス概要

ReflectionMethod
extends ReflectionFunctionAbstract
/* 定数 */
public const int ReflectionMethod::IS_STATIC;
public const int ReflectionMethod::IS_PUBLIC;
public const int ReflectionMethod::IS_PROTECTED;
public const int ReflectionMethod::IS_PRIVATE;
public const int ReflectionMethod::IS_ABSTRACT;
public const int ReflectionMethod::IS_FINAL;
/* プロパティ */
public string $class;
/* 継承したプロパティ */
public string $name;
/* メソッド */
public ReflectionMethod::__construct(objectstring $objectOrMethod, string $method)
public ReflectionMethod::__construct(string $classMethod)
public static static ReflectionMethod::createFromMethodName(string $method)
public static string ReflectionMethod::export(string $class, string $name, bool $return = false)
public Closure ReflectionMethod::getClosure(objectnull $object = null)
public ReflectionClass ReflectionMethod::getDeclaringClass()
public int ReflectionMethod::getModifiers()
public ReflectionMethod ReflectionMethod::getPrototype()
public bool ReflectionMethod::hasPrototype()
public mixed ReflectionMethod::invoke(objectnull $object, mixed ...$args)
public mixed ReflectionMethod::invokeArgs(objectnull $object, array $args)
public bool ReflectionMethod::isAbstract()
public bool ReflectionMethod::isConstructor()
public bool ReflectionMethod::isDestructor()
public bool ReflectionMethod::isFinal()
public bool ReflectionMethod::isPrivate()
public bool ReflectionMethod::isProtected()
public bool ReflectionMethod::isPublic()
public void ReflectionMethod::setAccessible(bool $accessible)
public string ReflectionMethod::__toString()
/* 継承したメソッド */
private void __clone()
public array getAttributes(stringnull $name = null, int $flags = 0)
public ReflectionClassnull getClosureScopeClass()
public objectnull getClosureThis()
public array getClosureUsedVariables()
public stringfalse getDocComment()
public intfalse getEndLine()
public ReflectionExtensionnull getExtension()
public stringfalse getExtensionName()
public stringfalse getFileName()
public string getName()
public string getNamespaceName()
public int getNumberOfParameters()
public int getNumberOfRequiredParameters()
public array getParameters()
public ReflectionTypenull getReturnType()
public string getShortName()
public intfalse getStartLine()
public array getStaticVariables()
public ReflectionTypenull getTentativeReturnType()
public bool hasReturnType()
public bool hasTentativeReturnType()
public bool inNamespace()
public bool isClosure()
public bool isDeprecated()
public bool isGenerator()
public bool isInternal()
public bool isStatic()
public bool isUserDefined()
public bool isVariadic()
public bool returnsReference()
abstract public void __toString()

プロパティ

name

メソッド名

class

クラス名

定義済み定数

ReflectionMethod の修飾子

ReflectionMethod::IS_STATIC

メソッドが static であることを示します。 PHP 7.4.0 より前のバージョンでは、この値は 1 でした。

ReflectionMethod::IS_PUBLIC

メソッドが public であることを示します。 PHP 7.4.0 より前のバージョンでは、この値は 256 でした。

ReflectionMethod::IS_PROTECTED

メソッドが protected であることを示します。 PHP 7.4.0 より前のバージョンでは、この値は 512 でした。

ReflectionMethod::IS_PRIVATE

メソッドが private であることを示します。 PHP 7.4.0 より前のバージョンでは、この値は 1024 でした。

ReflectionMethod::IS_ABSTRACT

メソッドが abstract であることを示します。 PHP 7.4.0 より前のバージョンでは、この値は 2 でした。

ReflectionMethod::IS_FINAL

メソッドが final であることを示します。 PHP 7.4.0 より前のバージョンでは、この値は 4 でした。

注意:

これらの定数の値は、PHP のバージョンが異なると変更される可能性があります。 これらの値を直接用いず、常に定数を使うことを推奨します。

変更履歴

バージョン 説明
8.0.0 ReflectionMethod::export は、削除されました。

ReflectionNamedType クラス

はじめに

クラス概要

ReflectionNamedType
extends ReflectionType
/* メソッド */
public string ReflectionNamedType::getName()
public bool ReflectionNamedType::isBuiltin()
/* 継承したメソッド */
public bool allowsNull()
public string __toString()

ReflectionObject クラス

はじめに

ReflectionObject クラスは オブジェクトについての情報を報告します。

クラス概要

ReflectionObject
extends ReflectionClass
/* 継承した定数 */
public const int ReflectionClass::IS_IMPLICIT_ABSTRACT;
public const int ReflectionClass::IS_EXPLICIT_ABSTRACT;
public const int ReflectionClass::IS_FINAL;
public const int ReflectionClass::IS_READONLY;
/* 継承したプロパティ */
public string $name;
/* メソッド */
public ReflectionObject::__construct(object $object)
/* 継承したメソッド */
public static string export(mixed $argument, bool $return = false)
public array getAttributes(stringnull $name = null, int $flags = 0)
public mixed getConstant(string $name)
public array getConstants(intnull $filter = null)
public ReflectionMethodnull getConstructor()
public array getDefaultProperties()
public stringfalse getDocComment()
public intfalse getEndLine()
public ReflectionExtensionnull getExtension()
public stringfalse getExtensionName()
public stringfalse getFileName()
public array getInterfaceNames()
public array getInterfaces()
public ReflectionMethod getMethod(string $name)
public array getMethods(intnull $filter = null)
public int getModifiers()
public string getName()
public string getNamespaceName()
public ReflectionClassfalse getParentClass()
public array getProperties(intnull $filter = null)
public ReflectionProperty getProperty(string $name)
public ReflectionClassConstantfalse getReflectionConstant(string $name)
public array getReflectionConstants(intnull $filter = null)
public string getShortName()
public intfalse getStartLine()
public array getStaticProperties()
public mixed getStaticPropertyValue(string $name, mixed &$def_value = ?)
public array getTraitAliases()
public array getTraitNames()
public array getTraits()
public bool hasConstant(string $name)
public bool hasMethod(string $name)
public bool hasProperty(string $name)
public bool implementsInterface(ReflectionClassstring $interface)
public bool inNamespace()
public bool isAbstract()
public bool isAnonymous()
public bool isCloneable()
public bool isEnum()
public bool isFinal()
public bool isInstance(object $object)
public bool isInstantiable()
public bool isInterface()
public bool isInternal()
public bool isIterable()
public bool isReadOnly()
public bool isSubclassOf(ReflectionClassstring $class)
public bool isTrait()
public bool isUserDefined()
public object newInstance(mixed ...$args)
public objectnull newInstanceArgs(array $args = [])
public object newInstanceWithoutConstructor()
public void setStaticPropertyValue(string $name, mixed $value)
public string __toString()

変更履歴

バージョン 説明
8.0.0 ReflectionObject::export は、削除されました。

ReflectionParameter クラス

はじめに

ReflectionParameter クラスは、 関数またはメソッドのパラメータに関する情報を取得します。

関数パラメータの内部を調べる際には、まず ReflectionFunction クラスまたは ReflectionMethod クラスのインスタンスを作成する必要があります。次に、 ReflectionFunctionAbstract::getParameters メソッドを使ってパラメータの配列を取得します。

クラス概要

ReflectionParameter
implements Reflector
/* プロパティ */
public string $name;
/* メソッド */
public __construct(stringarrayobject $function, intstring $param)
public bool allowsNull()
public bool canBePassedByValue()
private void __clone()
public static string export(string $function, string $parameter, bool $return = ?)
public array getAttributes(stringnull $name = null, int $flags = 0)
public ReflectionClassnull getClass()
public ReflectionClassnull getDeclaringClass()
public ReflectionFunctionAbstract getDeclaringFunction()
public mixed getDefaultValue()
public stringnull getDefaultValueConstantName()
public string getName()
public int getPosition()
public ReflectionTypenull getType()
public bool hasType()
public bool isArray()
public bool isCallable()
public bool isDefaultValueAvailable()
public bool isDefaultValueConstant()
public bool isOptional()
public bool isPassedByReference()
public bool isVariadic()
public string __toString()

プロパティ

name

パラメータ名。読み込み専用で、書き込もうとすると ReflectionException をスローします。

変更履歴

バージョン 説明
8.0.0 ReflectionParameter::export は、削除されました。

ReflectionProperty クラス

はじめに

ReflectionProperty クラスは クラスのプロパティについての情報を報告します。

クラス概要

ReflectionProperty
implements Reflector
/* 定数 */
public const int ReflectionProperty::IS_STATIC;
public const int ReflectionProperty::IS_READONLY;
public const int ReflectionProperty::IS_PUBLIC;
public const int ReflectionProperty::IS_PROTECTED;
public const int ReflectionProperty::IS_PRIVATE;
/* プロパティ */
public string $name;
public string $class;
/* メソッド */
public __construct(objectstring $class, string $property)
private void __clone()
public static string export(mixed $class, string $name, bool $return = ?)
public array getAttributes(stringnull $name = null, int $flags = 0)
public ReflectionClass getDeclaringClass()
public mixed getDefaultValue()
public stringfalse getDocComment()
public int getModifiers()
public string getName()
public ReflectionTypenull getType()
public mixed getValue(objectnull $object = null)
public bool hasDefaultValue()
public bool hasType()
public bool isDefault()
public bool isInitialized(objectnull $object = null)
public bool isPrivate()
public bool isPromoted()
public bool isProtected()
public bool isPublic()
public bool isReadOnly()
public bool isStatic()
public void setAccessible(bool $accessible)
public void setValue(object $object, mixed $value)
public string __toString()

プロパティ

name

プロパティ名。読み込み専用で、書き込もうとすると ReflectionException をスローします。

class

プロパティが定義されているクラス名。読み込み専用で、書き込もうとすると ReflectionException をスローします。

定義済み定数

ReflectionProperty の修飾子

ReflectionProperty::IS_STATIC

static プロパティを示します。 PHP 7.4.0 より前のバージョンでは、この値は 1 でした。

ReflectionProperty::IS_READONLY

readonly プロパティを示します。 PHP 8.1.0 以降で利用可能です。

ReflectionProperty::IS_PUBLIC

public プロパティを示します。 PHP 7.4.0 より前のバージョンでは、この値は 256 でした。

ReflectionProperty::IS_PROTECTED

protected プロパティを示します。 PHP 7.4.0 より前のバージョンでは、この値は 512 でした。

ReflectionProperty::IS_PRIVATE

private プロパティを示します。 PHP 7.4.0 より前のバージョンでは、この値は 1024 でした。

注意:

これらの定数の値は、PHP のバージョンが異なると変更される可能性があります。 これらの値を直接用いず、常に定数を使うことを推奨します。

変更履歴

バージョン 説明
8.0.0 ReflectionProperty::export は、削除されました。

ReflectionType クラス

はじめに

ReflectionType クラスは、 関数の引数や戻り値の型、 またはクラスのプロパティの型に関する情報を報告します。 リフレクション拡張モジュールでは、以下のサブクラスが宣言されています。

  • ReflectionNamedType (PHP 7.1.0 以降)
  • ReflectionUnionType (PHP 8.0.0 以降)
  • ReflectionIntersectionType (PHP 8.1.0 以降)

クラス概要

abstract ReflectionType
implements Stringable
/* メソッド */
public bool allowsNull()
public string __toString()

変更履歴

バージョン 説明
8.0.0 ReflectionType は、抽象クラスになり、 ReflectionType::isBuiltin は、 ReflectionNamedType::isBuiltin に移動しました。

ReflectionUnionType クラス

はじめに

クラス概要

ReflectionUnionType
extends ReflectionType
/* メソッド */
public array ReflectionUnionType::getTypes()
/* 継承したメソッド */
public bool allowsNull()
public string __toString()

ReflectionGenerator クラス

はじめに

ReflectionGenerator クラスは、ジェネレータに関する情報を報告します。

クラス概要

final ReflectionGenerator
/* メソッド */
public __construct(Generator $generator)
public string getExecutingFile()
public Generator getExecutingGenerator()
public int getExecutingLine()
public ReflectionFunctionAbstract getFunction()
public objectnull getThis()
public array getTrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT)

変更履歴

バージョン 説明
8.0.0 このクラスは final として定義され、 継承できなくなりました。

ReflectionFiber クラス

はじめに

クラス概要

final ReflectionFiber
/* メソッド */
public __construct(Fiber $fiber)
public callable getCallable()
public string getExecutingFile()
public int getExecutingLine()
public Fiber getFiber()
public array getTrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT)

ReflectionIntersectionType クラス

はじめに

クラス概要

ReflectionIntersectionType
extends ReflectionType
/* メソッド */
public array ReflectionIntersectionType::getTypes()
/* 継承したメソッド */
public bool allowsNull()
public string __toString()

ReflectionReference クラス

はじめに

ReflectionReference クラスは、リファレンスに関する情報を提供します。

クラス概要

final ReflectionReference
/* メソッド */
private __construct()
public static ReflectionReferencenull fromArrayElement(array $array, intstring $key)
public string getId()

ReflectionAttribute クラス

はじめに

ReflectionAttribute クラスは、 アトリビュート に関する情報を提供します。

クラス概要

ReflectionAttribute
implements Reflector
/* 定数 */
public const int ReflectionAttribute::IS_INSTANCEOF;
/* メソッド */
private __construct()
public array getArguments()
public string getName()
public int getTarget()
public bool isRepeated()
public object newInstance()

定義済み定数

ReflectionAttribute のフラグ

ReflectionAttribute::IS_INSTANCEOF

instanceof のチェックを使い、 アトリビュートを取得します。

注意:

これらの定数の値は、 PHP のバージョンによっては変更される可能性があります。 値そのものに依存せず、定数を使うことを推奨します。

Reflector インターフェイス

はじめに

Reflector は、 すべてのエクスポート可能なリフレクションクラスが実装しているインターフェイスです。

インターフェイス概要

Reflector extends Stringable
/* 継承したメソッド */
public string Stringable::__toString()

変更履歴

バージョン 説明
8.0.0 Reflector::export は、削除されました。
8.0.0 Reflector は、 Stringable を継承するようになりました。 これによって Reflector::__toString を置き換える形で、 Stringable::__toString が継承されるようになりました。

参考

  • Reflector::export

ReflectionException クラス

はじめに

ReflectionException クラスです。

クラス概要

ReflectionException
extends Exception
/* 継承したプロパティ */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private Throwablenull $previous = null;
/* 継承したメソッド */
public __construct(string $message = "", int $code = 0, Throwablenull $previous = null)
final public string getMessage()
final public Throwablenull getPrevious()
final public int getCode()
final public string getFile()
final public int getLine()
final public array getTrace()
final public string getTraceAsString()
public string __toString()
private void __clone()