The AllowDynamicProperties attributeIntroductionThis attribute is used to mark classes that allow dynamic properties.
Class synopsis
#[\Attribute(\Attribute::TARGET_CLASS)]
final
AllowDynamicProperties
/* Methods */
public __construct()
ExamplesExample #1 AllowDynamicProperties with a dynamic property
To enable dynamic properties, add Example #2 AllowDynamicProperties with non-existing property As of PHP 8.2.0, the declaration is required unless the class uses this attribute. Creating an undeclared property on such a class emits a deprecation notice. Output of the above example in PHP 8.2: Deprecated: Creation of dynamic property InvalidExample::$myUnknownProperty is deprecated in file on line 5 Example #3 AllowDynamicProperties with non-existing property in inherited class Output of the above example in PHP 8.2: Deprecated: Creation of dynamic property DefaultBehaviour::$nonExistingProp is deprecated in file on line 12 See Also
|