The ReflectionProperty class

(PHP 5, PHP 7, PHP 8)

Introduction

The ReflectionProperty class reports information about class properties.

Class synopsis

classReflectionPropertyimplementsReflector {
publicconstintIS_STATIC;
publicconstintIS_READONLY;
publicconstintIS_PUBLIC;
publicconstintIS_PROTECTED;
publicconstintIS_PRIVATE;
public__construct(object|string$class, string$property)
private__clone(): void
publicstaticexport(mixed$class, string$name, bool$return = ?): string
publicgetAttributes(?string$name = null, int$flags = 0): array
publicgetModifiers(): int
publicgetName(): string
publicgetValue(?object$object = null): mixed
publichasType(): bool
publicisDefault(): bool
publicisInitialized(?object$object = null): bool
publicisPrivate(): bool
publicisPromoted(): bool
publicisProtected(): bool
publicisPublic(): bool
publicisReadOnly(): bool
publicisStatic(): bool
publicsetAccessible(bool$accessible): void
publicsetValue(object$object, mixed$value): void
}

Properties

name

Name of the property. Read-only, throws ReflectionException in attempt to write.

class

Name of the class where the property is defined. Read-only, throws ReflectionException in attempt to write.

Predefined Constants

ReflectionProperty Modifiers

ReflectionProperty::IS_STATIC

Indicates static properties. Prior to PHP 7.4.0, the value was 1.

ReflectionProperty::IS_READONLY

Indicates readonly properties. Available as of PHP 8.1.0.

ReflectionProperty::IS_PUBLIC

Indicates public properties. Prior to PHP 7.4.0, the value was 256.

ReflectionProperty::IS_PROTECTED

Indicates protected properties. Prior to PHP 7.4.0, the value was 512.

ReflectionProperty::IS_PRIVATE

Indicates private properties. Prior to PHP 7.4.0, the value was 1024.

Note:

The values of these constants may change between PHP versions. It is recommended to always use the constants and not rely on the values directly.

Changelog

VersionDescription
8.0.0ReflectionProperty::export() was removed.

Table of Contents

To Top