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
class-string $class

Methods

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

Checks if property has a default value declared

mixed
getDefaultValue()

Returns the default value declared for a property

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

Gets Attributes

bool
isReadOnly()

Checks if property is readonly

mixed
getRawValue(object $object)

Returns the value of a property, bypassing a get hook if defined

void
setRawValue(object $object, mixed $value)

Sets the value of a property, bypassing a set hook if defined

bool
isAbstract()

Determines if a property is abstract

bool
isVirtual()

Determines if a property is virtual

getSettableType()

Returns the parameter type of a setter hook

bool
hasHooks()

Returns whether the property has any hooks defined

array
getHooks()

Returns an array of all hooks on this property

bool
hasHook(PropertyHookType $type)

Returns whether the property has a given hook defined

getHook(PropertyHookType $type)

Returns a reflection object for a specified hook

bool
isPrivateSet()

Checks if property is private for writing

bool
isProtectedSet()

Checks whether the property is protected for writing

void
setRawValueWithoutLazyInitialization(object $object, mixed $value)

Set raw property value without triggering lazy initialization

void
skipLazyInitialization(object $object)

Marks property as non-lazy

bool
isDynamic()

Checks if property is a dynamic property

bool
isFinal()

Determines if this property is final or not

bool
isLazy(object $object)

Checks whether a property is lazy

string
getMangledName()

Gets the mangled name of the property

bool
isReadable(string|null $scope, object|null $object = null)

No description

bool
isWritable(string|null $scope, object|null $object = null)

No description

Details

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

Construct a ReflectionProperty object

Parameters

class-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.

Exceptions

ReflectionException

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

Checks if property has a default value declared

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

Return Value

bool

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.

mixed getDefaultValue()

Since: 8.0

Returns the default value declared for a property

Gets the implicit or explicitly declared default value for a property.

Return Value

mixed

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 uninitialized typed property. Use ReflectionProperty::hasDefaultValue to detect the difference.

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

Since: 8.0

Gets Attributes

Returns all attributes declared on this class property as an array of ReflectionAttribute.

Parameters

string|null $name

Name of an attribute class

int $flags

Сriteria by which the attribute is searched.

Return Value

array

Array of attributes, as a ReflectionAttribute object.

bool isReadOnly()

Since: 8.1

Checks if property is readonly

Checks whether the property is readonly.

Return Value

bool

true if the property is readonly, false otherwise.

mixed getRawValue(object $object)

Since: 8.4

Returns the value of a property, bypassing a get hook if defined

Parameters

object $object

Return Value

mixed

Exceptions

Error

void setRawValue(object $object, mixed $value)

Since: 8.4

Sets the value of a property, bypassing a set hook if defined

Parameters

object $object
mixed $value

Return Value

void

Exceptions

Error

bool isAbstract()

Since: 8.4

Determines if a property is abstract

Return Value

bool

bool isVirtual()

Since: 8.4

Determines if a property is virtual

Return Value

bool

ReflectionType|null getSettableType()

Since: 8.4

Returns the parameter type of a setter hook

Returns the parameter type of a set hook. If no set hook is defined, it behaves identically to ReflectionProperty::getType.

Return Value

ReflectionType|null

bool hasHooks()

Since: 8.4

Returns whether the property has any hooks defined

Return Value

bool

array getHooks()

Since: 8.4

Returns an array of all hooks on this property

Returns a list of all hooks on this property.

Return Value

array

bool hasHook(PropertyHookType $type)

Since: 8.4

Returns whether the property has a given hook defined

Parameters

PropertyHookType $type

Return Value

bool

ReflectionMethod|null getHook(PropertyHookType $type)

Since: 8.4

Returns a reflection object for a specified hook

Gets the reflection of the property's hook, if any.

Parameters

PropertyHookType $type

Return Value

ReflectionMethod|null

bool isPrivateSet()

Since: 8.4

Checks if property is private for writing

Checks whether the property is private for writing.

Return Value

bool

bool isProtectedSet()

Since: 8.4

Checks whether the property is protected for writing

Return Value

bool

void setRawValueWithoutLazyInitialization(object $object, mixed $value)

Since: 8.4

Set raw property value without triggering lazy initialization

Sets (changes) the property's value without triggering lazy initialization and without calling hook functions. The property is marked as non-lazy and can be accessed afterwards without triggering lazy initialization. The property must not be dynamic, static, or virtual, and the object must be an instance of a user defined class or stdClass.

Parameters

object $object
mixed $value

Return Value

void

void skipLazyInitialization(object $object)

Since: 8.4

Marks property as non-lazy

Marks a property as non-lazy such that it can be accessed directly without triggering lazy initialization. The property is initialized to its default value, if any. The property must not be dynamic, static, or virtual, and the object must be an instance of a user defined class or stdClass.

Parameters

object $object

Return Value

void

bool isDynamic()

Since: 8.4

Checks if property is a dynamic property

Checks whether the property was declared at run-time, or whether the property was declared at compile-time.

Return Value

bool

bool isFinal()

Since: 8.4

Determines if this property is final or not

Returns whether the property is final. If the property is marked private(set), then it will also be implicitly final.

Return Value

bool

bool isLazy(object $object)

Since: 8.4

Checks whether a property is lazy

Parameters

object $object

Return Value

bool

string getMangledName()

Since: 8.5

Gets the mangled name of the property

Returns the mangled (internal) name of the property, which encodes the visibility scope for private and protected properties.

Return Value

string

bool isReadable(string|null $scope, object|null $object = null)

Since: 8.6

No description

Parameters

string|null $scope
object|null $object

Return Value

bool

bool isWritable(string|null $scope, object|null $object = null)

Since: 8.6

No description

Parameters

string|null $scope
object|null $object

Return Value

bool