trait ReadOnlyPropertiesTrait

This trait defines magic getters and setters for read-only object's properties

The read-only properties list MUST be declared via the setReadOnlyProperties() method of this class (see the documentation of the method for more information). Keep in mind that the magic methods defined here will ONLY consider read-only properties (other properties must be handled by the child class).

Methods

void
setReadOnlyProperties( array $data)

Defines the read-only properties names and accessors.

mixed
__get( string $name)

Magic getter for read-only properties.

void
__set( string $name, mixed $value)

Magic setter to avoid setting read-only properties.

void
__unset( string $name)

Magic un-setter to avoid un-setting read-only properties.

Details

at line 54
void setReadOnlyProperties( array $data)

Defines the read-only properties names and accessors.

Each key => value pair of the $data array must be constructed like:

  • key is the name of the property (MUST be defined with protected access in the child class)
  • value is an accessor for that property: the name of the access method if it exists or true for the default $obj->$key accessor.

Parameters

array $data This is the table of read-only properties

Return Value

void

Exceptions

InvalidArgumentException if the $data array is malformed

at line 85
mixed __get( string $name)

Magic getter for read-only properties.

This will trigger a notice if the property can not be accessed.

Parameters

string $name

Return Value

mixed

at line 109
void __set( string $name, mixed $value)

Magic setter to avoid setting read-only properties.

Parameters

string $name
mixed $value

Return Value

void

Exceptions

ReflectionException if trying to set a read-only property

at line 125
void __unset( string $name)

Magic un-setter to avoid un-setting read-only properties.

Parameters

string $name

Return Value

void

Exceptions

ReflectionException if trying to unset a read-only property