class ReflectionProperty implements Reflector (View source)

The ReflectionProperty class reports information about a classes properties.

Constants

IS_ABSTRACT Since: 8.4

IS_VIRTUAL Since: 8.4

IS_STATIC

Indicates that the property is static.

IS_PUBLIC

Indicates that the property is public.

IS_PROTECTED

Indicates that the property is protected.

IS_PRIVATE

Indicates that the property is private.

IS_READONLY Since: 8.1

IS_PROTECTED_SET Since: 8.4

IS_PRIVATE_SET Since: 8.4

IS_FINAL Since: 8.4

Properties

string $name
string $class

Methods

__construct(string|object $class, string $property)

Construct a ReflectionProperty object

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

Export

string
__toString()

To string

string
getName()

Gets property name

mixed
getValue(object|null $object = null)

Gets value

void
setValue(mixed $objectOrValue, mixed $value)

Set property value

bool
isPublic()

Checks if property is public

bool
isPrivate()

Checks if property is private

bool
isProtected()

Checks if property is protected

bool
isStatic()

Checks if property is static

bool
isDefault()

Checks if default value

int
getModifiers()

Gets modifiers

getDeclaringClass()

Gets declaring class

string|false
getDocComment()

Gets doc comment

void
setAccessible(bool $accessible)

Set property accessibility This method is no-op starting from PHP 8.1

getType()

Gets property type

bool
hasType()

Checks if property has type

bool
isInitialized(object|null $object = null)

Checks if property is initialized

bool
isPromoted()

Returns information about whether the property was promoted.

bool
hasDefaultValue()

No description

mixed
getDefaultValue()

No description

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

No description

bool
isReadOnly()

No description

mixed
getRawValue(object $object)

No description

void
setRawValue(object $object, mixed $value)

No description

bool
isAbstract()

No description

bool
isVirtual()

No description

getSettableType()

No description

bool
hasHooks()

No description

array
getHooks()

No description

bool
hasHook(PropertyHookType $type)

No description

getHook(PropertyHookType $type)

No description

bool
isPrivateSet()

No description

bool
isProtectedSet()

No description

void
setRawValueWithoutLazyInitialization(object $object, mixed $value)

No description

void
skipLazyInitialization(object $object)

No description

bool
isDynamic()

No description

bool
isFinal()

No description

bool
isLazy(object $object)

No description

Details

__construct(string|object $class, string $property)

Construct a ReflectionProperty object

Parameters

string|object $class

The class name, that contains the property.

string $property

The name of the property being reflected.

Exceptions

ReflectionException

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

Export

Parameters

mixed $class

The reflection to export.

string $name

The property name.

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()

To string

Return Value

string

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

string getName()

Gets property name

Return Value

string

The name of the reflected property.

mixed getValue(object|null $object = null)

Gets value

Parameters

object|null $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 {ReflectionClass

Return Value

mixed

The current value of the property.

void setValue(mixed $objectOrValue, mixed $value)

Set property value

Parameters

mixed $objectOrValue

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.

mixed $value

[optional] The new value.

Return Value

void

No value is returned.

bool isPublic()

Checks if property is public

Return Value

bool

Return {\true} if the property is public, {\false} otherwise.

bool isPrivate()

Checks if property is private

Return Value

bool

Return {\true} if the property is private, {\false} otherwise.

bool isProtected()

Checks if property is protected

Return Value

bool

Returns {\true} if the property is protected, {\false} otherwise.

bool isStatic()

Checks if property is static

Return Value

bool

Returns {\true} if the property is static, {\false} otherwise.

bool isDefault()

Checks if default value

Return Value

bool

Returns {\true} if the property was declared at compile-time, or {\false} if it was created at run-time.

int getModifiers()

Gets modifiers

Return Value

int

A numeric representation of the modifiers.

ReflectionClass getDeclaringClass()

Gets declaring class

Return Value

ReflectionClass

A {\ReflectionClass} object.

string|false getDocComment()

Gets doc comment

Return Value

string|false

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

void setAccessible(bool $accessible)

Set property accessibility This method is no-op starting from PHP 8.1

Parameters

bool $accessible

A boolean {\true} to allow accessibility, or {\false}

Return Value

void

No value is returned.

ReflectionType|null getType()

Since: 7.4

Gets property type

Return Value

ReflectionType|null

Returns a {\ReflectionType} if the property has a type, and {\null} otherwise.

bool hasType()

Since: 7.4

Checks if property has type

Return Value

bool

Returns {\true} if a type is specified, {\false} otherwise.

bool isInitialized(object|null $object = null)

Since: 7.4

Checks if property is initialized

Parameters

object|null $object

If the property is non-static an object must be provided to fetch the property from.

Return Value

bool

Returns {\false} for typed properties prior to initialization, and for properties that have been explicitly {\unset()}. For all other properties {\true} will be returned.

bool isPromoted()

Since: 8.0

Returns information about whether the property was promoted.

Return Value

bool

Returns {\true} if the property was promoted or {\false} instead.

bool hasDefaultValue()

Since: 8.0

No description

Return Value

bool

mixed getDefaultValue()

Since: 8.0

No description

Return Value

mixed

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 isReadOnly()

Since: 8.1

No description

Return Value

bool

mixed getRawValue(object $object)

Since: 8.4

No description

Parameters

object $object

Return Value

mixed

void setRawValue(object $object, mixed $value)

Since: 8.4

No description

Parameters

object $object
mixed $value

Return Value

void

bool isAbstract()

Since: 8.4

No description

Return Value

bool

bool isVirtual()

Since: 8.4

No description

Return Value

bool

ReflectionType|null getSettableType()

Since: 8.4

No description

Return Value

ReflectionType|null

bool hasHooks()

Since: 8.4

No description

Return Value

bool

array getHooks()

Since: 8.4

No description

Return Value

array

bool hasHook(PropertyHookType $type)

Since: 8.4

No description

Parameters

PropertyHookType $type

Return Value

bool

ReflectionMethod|null getHook(PropertyHookType $type)

Since: 8.4

No description

Parameters

PropertyHookType $type

Return Value

ReflectionMethod|null

bool isPrivateSet()

Since: 8.4

No description

Return Value

bool

bool isProtectedSet()

Since: 8.4

No description

Return Value

bool

void setRawValueWithoutLazyInitialization(object $object, mixed $value)

Since: 8.4

No description

Parameters

object $object
mixed $value

Return Value

void

void skipLazyInitialization(object $object)

Since: 8.4

No description

Parameters

object $object

Return Value

void

bool isDynamic()

Since: 8.4

No description

Return Value

bool

bool isFinal()

Since: 8.4

No description

Return Value

bool

bool isLazy(object $object)

Since: 8.4

No description

Parameters

object $object

Return Value

bool