Creation of dynamic property %s::$%s is deprecated¶
Description¶
When PHP uses an undefined property for a writing access, it used to create that property on the fly. The property is created with public visibility, not type nor default value.
Since PHP 8.2, this is a deprecated feature. In a later version, by default, dynamic properties will be forbidden, and activated case by case, using sdtClass or the #[AllowDynamicProperties]
attribute.
Example¶
<?php
class X {
public $property = 1;
}
$x = new X;
$x->property = 2;
// This is a dynamic property
$x->other = 3;
?>
Solutions¶
Declare the property in the class definition.
Create an array and store the properties there.
Create a stdClass object and store the properties there.
Add the
#[AllowDynamicProperties]
.