class ReflectionClass implements Reflector (View source)

Constants

IS_IMPLICIT_ABSTRACT

Indicates class that is abstract because it has some abstract methods.

IS_EXPLICIT_ABSTRACT

Indicates class that is abstract because of its definition.

IS_FINAL

Indicates final class.

IS_READONLY Since: 8.2

SKIP_INITIALIZATION_ON_SERIALIZE Since: 8.4

SKIP_DESTRUCTOR Since: 8.4

Properties

T> $name

Methods

__construct(T>|T $objectOrClass)

Constructs a ReflectionClass

static string|null
export(mixed $argument, bool $return = false)

Exports a reflected class

string
__toString()

Returns the string representation of the ReflectionClass object.

string
getName()

Gets class name

bool
isInternal()

Checks if class is defined internally by an extension, or the core

bool
isUserDefined()

Checks if user defined

bool
isInstantiable()

Checks if the class is instantiable

bool
isCloneable()

Returns whether this class is cloneable

string|false
getFileName()

Gets the filename of the file in which the class has been defined

int|false
getStartLine()

Gets starting line number

int|false
getEndLine()

Gets end line

string|false
getDocComment()

Gets doc comments

getConstructor()

Gets the constructor of the class

bool
hasMethod(string $name)

Checks if method is defined

getMethod(string $name)

Gets a ReflectionMethod for a class method.

array
getMethods(int|null $filter = null)

Gets an array of methods for the class.

bool
hasProperty(string $name)

Checks if property is defined

getProperty(string $name)

Gets a ReflectionProperty for a class's property

array
getProperties(int|null $filter = null)

Gets properties

ReflectionClassConstant|false
getReflectionConstant(string $name)

Gets a ReflectionClassConstant for a class's property

array
getReflectionConstants(int|null $filter = null)

Gets class constants

bool
hasConstant(string $name)

Checks if constant is defined

array
getConstants(int|null $filter = null)

Gets constants

mixed
getConstant(string $name)

Gets defined constant

array
getInterfaces()

Gets the interfaces

array
getInterfaceNames()

Gets the interface names

bool
isAnonymous()

Checks if the class is anonymous

bool
isInterface()

Checks if the class is an interface

array
getTraits()

Returns an array of traits used by this class

array
getTraitNames()

Returns an array of names of traits used by this class

array
getTraitAliases()

Returns an array of trait aliases

bool
isTrait()

Returns whether this is a trait

bool
isAbstract()

Checks if class is abstract

bool
isFinal()

Checks if class is final

bool
isReadOnly()

No description

int
getModifiers()

Gets modifiers

bool
isInstance(object $object)

Checks class for instance

T
newInstance(mixed ...$args)

Creates a new class instance from given arguments.

object
newInstanceWithoutConstructor()

Creates a new class instance without invoking the constructor.

object|null
newInstanceArgs(array $args = [])

Creates a new class instance from given arguments.

ReflectionClass|false
getParentClass()

Gets parent class

bool
isSubclassOf(string|ReflectionClass $class)

Checks if a subclass

array|null
getStaticProperties()

Gets static properties

mixed
getStaticPropertyValue(string $name, mixed $default)

Gets static property value

void
setStaticPropertyValue(string $name, mixed $value)

Sets static property value

array
getDefaultProperties()

Gets default properties

bool
isIterateable()

An alias of {ReflectionClass method.

bool
isIterable()

Check whether this class is iterable

bool
implementsInterface(string $interface)

Checks whether it implements an interface.

getExtension()

Gets a ReflectionExtension object for the extension which defined the class

string|false
getExtensionName()

Gets the name of the extension which defined the class

bool
inNamespace()

Checks if in namespace

string
getNamespaceName()

Gets namespace name

string
getShortName()

Gets short name

array
getAttributes(string|null $name = null, int $flags = 0)

No description

bool
isEnum()

No description

object
newLazyGhost(callable $initializer, int $options = 0)

No description

object
newLazyProxy(callable $factory, int $options = 0)

No description

void
resetAsLazyGhost(object $object, callable $initializer, int $options = 0)

No description

void
resetAsLazyProxy(object $object, callable $factory, int $options = 0)

No description

object
initializeLazyObject(object $object)

No description

bool
isUninitializedLazyObject(object $object)

No description

object
markLazyObjectAsInitialized(object $object)

No description

callable|null
getLazyInitializer(object $object)

No description

Details

__construct(T>|T $objectOrClass)

Constructs a ReflectionClass

Parameters

T>|T $objectOrClass

Either a string containing the name of the class to reflect, or an object.

Exceptions

ReflectionException

static string|null export(mixed $argument, bool $return = false)

Exports a reflected class

Parameters

mixed $argument

The reflection to export.

bool $return

Setting to {\true} will return the export, as opposed to emitting it. Setting to {\false} (the default) will do the opposite.

Return Value

string|null

string __toString()

Returns the string representation of the ReflectionClass object.

Return Value

string

Returns string representation of the object that implements this interface (and/or "__toString" magic method).

string getName()

Gets class name

Return Value

string

The class name.

bool isInternal()

Checks if class is defined internally by an extension, or the core

Return Value

bool

Returns {\true} on success or {\false} on failure.

bool isUserDefined()

Checks if user defined

Return Value

bool

Returns {\true} on success or {\false} on failure.

bool isInstantiable()

Checks if the class is instantiable

Return Value

bool

Returns {\true} on success or {\false} on failure.

bool isCloneable()

Since: 5.4

Returns whether this class is cloneable

Return Value

bool

Returns {\true} if the class is cloneable, {\false} otherwise.

string|false getFileName()

Gets the filename of the file in which the class has been defined

Return Value

string|false

the filename of the file in which the class has been defined. If the class is defined in the PHP core or in a PHP extension, {\false} is returned.

int|false getStartLine()

Gets starting line number

Return Value

int|false

The starting line number, as an integer.

int|false getEndLine()

Gets end line

Return Value

int|false

The ending line number of the user defined class, or {\false} if unknown.

string|false getDocComment()

Gets doc comments

Return Value

string|false

The doc comment if it exists, otherwise {\false}

ReflectionMethod|null getConstructor()

Gets the constructor of the class

Return Value

ReflectionMethod|null

A {\ReflectionMethod} object reflecting the class' constructor, or {\null} if the class has no constructor.

bool hasMethod(string $name)

Checks if method is defined

Parameters

string $name

Name of the method being checked for.

Return Value

bool

Returns {\true} if it has the method, otherwise {\false}

ReflectionMethod getMethod(string $name)

Gets a ReflectionMethod for a class method.

Parameters

string $name

The method name to reflect.

Return Value

ReflectionMethod

A {\ReflectionMethod}

Exceptions

ReflectionException

array getMethods(int|null $filter = null)

Gets an array of methods for the class.

Parameters

int|null $filter

Filter the results to include only methods with certain attributes. Defaults to no filtering.

Return Value

array

An array of {\ReflectionMethod} objects reflecting each method.

bool hasProperty(string $name)

Checks if property is defined

Parameters

string $name

Name of the property being checked for.

Return Value

bool

Returns {\true} if it has the property, otherwise {\false}

ReflectionProperty getProperty(string $name)

Gets a ReflectionProperty for a class's property

Parameters

string $name

The property name.

Return Value

ReflectionProperty

A {\ReflectionProperty}

Exceptions

ReflectionException

array getProperties(int|null $filter = null)

Gets properties

Parameters

int|null $filter

The optional filter, for filtering desired property types. It's configured using the {\ReflectionProperty} constants, and defaults to all property types.

Return Value

array

ReflectionClassConstant|false getReflectionConstant(string $name)

Since: 7.1

Gets a ReflectionClassConstant for a class's property

Parameters

string $name

The class constant name.

Return Value

ReflectionClassConstant|false

A {\ReflectionClassConstant}.

array getReflectionConstants(int|null $filter = null)

Since: 7.1

Gets class constants

Parameters

int|null $filter

[optional] allows the filtering of constants defined in a class by their visibility. Since 8.0.

Return Value

array

An array of ReflectionClassConstant objects.

bool hasConstant(string $name)

Checks if constant is defined

Parameters

string $name

The name of the constant being checked for.

Return Value

bool

Returns {\true} if the constant is defined, otherwise {\false}

array getConstants(int|null $filter = null)

Gets constants

Parameters

int|null $filter

[optional] allows the filtering of constants defined in a class by their visibility. Since 8.0.

Return Value

array

An array of constants, where the keys hold the name and the values the value of the constants.

mixed getConstant(string $name)

Gets defined constant

Parameters

string $name

Name of the constant.

Return Value

mixed

Value of the constant with the name name. Returns {\false} if the constant was not found in the class.

array getInterfaces()

Gets the interfaces

Return Value

array

An associative array of interfaces, with keys as interface names and the array values as {\ReflectionClass} objects.

array getInterfaceNames()

Gets the interface names

Return Value

array

A numerical array with interface names as the values.

bool isAnonymous()

Since: 7.0

Checks if the class is anonymous

Return Value

bool

Returns {\true} on success or {\false} on failure.

bool isInterface()

Checks if the class is an interface

Return Value

bool

Returns {\true} on success or {\false} on failure.

array getTraits()

Since: 5.4

Returns an array of traits used by this class

Return Value

array

an array with trait names in keys and instances of trait's {\ReflectionClass} in values.

array getTraitNames()

Since: 5.4

Returns an array of names of traits used by this class

Return Value

array

An array with trait names in values. Returns {\null} in case of an error.

array getTraitAliases()

Since: 5.4

Returns an array of trait aliases

Return Value

array

an array with new method names in keys and original names (in the format "TraitName::original") in values. Returns {\null} in case of an error.

bool isTrait()

Since: 5.4

Returns whether this is a trait

Return Value

bool

Returns {\true} if this is a trait, {\false} otherwise. Returns {\null} in case of an error.

bool isAbstract()

Checks if class is abstract

Return Value

bool

Returns {\true} on success or {\false} on failure.

bool isFinal()

Checks if class is final

Return Value

bool

Returns {\true} on success or {\false} on failure.

bool isReadOnly()

No description

Return Value

bool

int getModifiers()

Gets modifiers

Return Value

int

bitmask of modifier constants.

bool isInstance(object $object)

Checks class for instance

Parameters

object $object

The object being compared to.

Return Value

bool

Returns {\true} on success or {\false} on failure.

T newInstance(mixed ...$args)

Creates a new class instance from given arguments.

Parameters

mixed ...$args

Accepts a variable number of arguments which are passed to the class constructor, much like {\call_user_func}

Return Value

T

a new instance of the class.

Exceptions

ReflectionException

object newInstanceWithoutConstructor()

Since: 5.4

Creates a new class instance without invoking the constructor.

Return Value

object

a new instance of the class.

Exceptions

ReflectionException

object|null newInstanceArgs(array $args = [])

Since: 5.1.3

Creates a new class instance from given arguments.

Parameters

array $args

The parameters to be passed to the class constructor as an array.

Return Value

object|null

a new instance of the class.

Exceptions

ReflectionException

ReflectionClass|false getParentClass()

Gets parent class

Return Value

ReflectionClass|false

A {\ReflectionClass} or {\false} if there's no parent.

bool isSubclassOf(string|ReflectionClass $class)

Checks if a subclass

Parameters

string|ReflectionClass $class

Either the name of the class as string or a {\ReflectionClass} object of the class to check against.

Return Value

bool

{\true} on success or {\false} on failure.

array|null getStaticProperties()

Gets static properties

Return Value

array|null

The static properties, as an array where the keys hold the name and the values the value of the properties.

mixed getStaticPropertyValue(string $name, mixed $default)

Gets static property value

Parameters

string $name

The name of the static property for which to return a value.

mixed $default

[optional] A default value to return in case the class does not declare a static property with the given name. If the property does not exist and this argument is omitted, a {\ReflectionException} is thrown.

Return Value

mixed

The value of the static property.

void setStaticPropertyValue(string $name, mixed $value)

Sets static property value

Parameters

string $name

Property name.

mixed $value

New property value.

Return Value

void

No value is returned.

array getDefaultProperties()

Gets default properties

Return Value

array

An array of default properties, with the key being the name of the property and the value being the default value of the property or {\null} if the property doesn't have a default value. The function does not distinguish between static and non static properties and does not take visibility modifiers into account.

bool isIterateable()

An alias of {ReflectionClass method.

Return Value

bool

Returns {\true} on success or {\false} on failure.

bool isIterable()

Since: 7.2

Check whether this class is iterable

Return Value

bool

Returns {\true} on success or {\false} on failure.

bool implementsInterface(string $interface)

Checks whether it implements an interface.

Parameters

string $interface

The interface name.

Return Value

bool

Returns {\true} on success or {\false} on failure.

ReflectionExtension|null getExtension()

Gets a ReflectionExtension object for the extension which defined the class

Return Value

ReflectionExtension|null

A {\ReflectionExtension} object representing the extension which defined the class, or {\null} for user-defined classes.

string|false getExtensionName()

Gets the name of the extension which defined the class

Return Value

string|false

The name of the extension which defined the class, or {\false} for user-defined classes.

bool inNamespace()

Checks if in namespace

Return Value

bool

{\true} on success or {\false} on failure.

string getNamespaceName()

Gets namespace name

Return Value

string

The namespace name.

string getShortName()

Gets short name

Return Value

string

The class short name.

array getAttributes(string|null $name = null, int $flags = 0)

Since: 8.0

No description

Parameters

string|null $name

Name of an attribute class

int $flags

Сriteria by which the attribute is searched.

Return Value

array

bool isEnum()

No description

Return Value

bool

object newLazyGhost(callable $initializer, int $options = 0)

Since: 8.4

No description

Parameters

callable $initializer
int $options

Return Value

object

object newLazyProxy(callable $factory, int $options = 0)

Since: 8.4

No description

Parameters

callable $factory
int $options

Return Value

object

void resetAsLazyGhost(object $object, callable $initializer, int $options = 0)

Since: 8.4

No description

Parameters

object $object
callable $initializer
int $options

Return Value

void

void resetAsLazyProxy(object $object, callable $factory, int $options = 0)

Since: 8.4

No description

Parameters

object $object
callable $factory
int $options

Return Value

void

object initializeLazyObject(object $object)

Since: 8.4

No description

Parameters

object $object

Return Value

object

bool isUninitializedLazyObject(object $object)

Since: 8.4

No description

Parameters

object $object

Return Value

bool

object markLazyObjectAsInitialized(object $object)

Since: 8.4

No description

Parameters

object $object

Return Value

object

callable|null getLazyInitializer(object $object)

Since: 8.4

No description

Parameters

object $object

Return Value

callable|null