(PHP 8 >= 8.2.0)
This attribute is used to mark classes that allow dynamic properties.
ΠΠ°ΡΠ²Π°ΠΆΠ΅Π½Π½Ρ: Although attributes themselves are not inherited, the effect of the
AllowDynamicPropertiesattribute is inherited. Child classes of a class marked with this attribute will also allow dynamic properties, even if they do not explicitly declare the attribute.
Dynamic properties are deprecated as of PHP 8.2.0, thus using them without marking the class with this attribute will emit a deprecation notice.
ΠΡΠΈΠΊΠ»Π°Π΄ #1 AllowDynamicProperties with non-existing property
<?php
class DefaultBehaviour { }
#[\AllowDynamicProperties]
class ClassAllowsDynamicProperties { }
$o1 = new DefaultBehaviour();
$o2 = new ClassAllowsDynamicProperties();
$o1->nonExistingProp = true;
$o2->nonExistingProp = true;
?>Π PHP 8.2 ΠΏΠΎΠ΄Π°Π½ΠΈΠΉ Π²ΠΈΡΠ΅ ΠΏΡΠΈΠΊΠ»Π°Π΄ Π²ΠΈΠ²Π΅Π΄Π΅:
Deprecated: Creation of dynamic property DefaultBehaviour::$nonExistingProp is deprecated in file on line 10
ΠΡΠΈΠΊΠ»Π°Π΄ #2 AllowDynamicProperties with non-existing property in inherited class
<?php
class DefaultBehaviour { }
#[\AllowDynamicProperties]
class ClassAllowsDynamicProperties { }
class InheritedClassAllowsDynamicProperties extends ClassAllowsDynamicProperties { }
$o1 = new DefaultBehaviour();
$o2 = new InheritedClassAllowsDynamicProperties();
$o1->nonExistingProp = true;
$o2->nonExistingProp = true;
?>Π PHP 8.2 ΠΏΠΎΠ΄Π°Π½ΠΈΠΉ Π²ΠΈΡΠ΅ ΠΏΡΠΈΠΊΠ»Π°Π΄ Π²ΠΈΠ²Π΅Π΄Π΅:
Deprecated: Creation of dynamic property DefaultBehaviour::$nonExistingProp is deprecated in file on line 12