Allow Dynamic Properties
This is a native PHP attribute, which tells the engine that a class can dynamically create properties without declaring them.
This attribute may be added to any class. It is not necessary with stdClass.
The attributes allow any dynamic property: there is no way to restrict this to a set of names or a number without other means.
<?php
class Elephpant {
function trumpet() {
// creation of a property, without prior definition
// This yields an error
$this->trunkLength = 1;
}
}
#[AllowDynamicProperty]
class Herd {
function trumpet() {
// creation of a property, without prior definition
// This doesn't yields an error
$this->trunkLength = 1;
}
}
class Waterhole extends Stdclass {
function trumpet() {
// creation of a property, without prior definition
// This doesn't yields an error, yet no attribute
$this->trunkLength = 1;
}
}
?>