PHP 8.2: AllowDynamicProperties
Attribute
#[AllowDynamicProperties]
is a new attribute added in PHP 8.2, that avoids the deprecation notice on dynamic properties.
#[AllowDynamicProperties]
property is declared in the global namespace. It does not accept any parameters.
When a class is declared with the #[AllowDynamicProperties]
attribute, it no longer emits dynamic property deprecation notices:
+ #[AllowDynamicProperties]
class User() {}
$user = new User();
$user->foo = 'bar';
Built-in classes with AllowDynamicProperties
attribute
PHP's built-in stdClass
has the #[AllowDynamicProperties]
attribute added.