-
Bug
-
Resolution: Duplicate
-
Critical
-
None
-
4.2
-
None
-
MOODLE_402_STABLE
From PHP 8.2, if someone tries to set a value for a class property which does not have a definitino, a deprecation notice will be emitted. For example:
class User {
|
private int $uid;
|
}
|
|
$user = new User();
|
$user->name = 'Foo';
|
Deprecated: Creation of dynamic property User::$name is deprecated in ... on line ...
|
Also from internally:
class User {
|
public function __construct() {
|
$this->name = 'test';
|
}
|
}
|
|
new User();
|
Deprecated: Creation of dynamic property User::$name is deprecated in ... on line ...
|
Much more detail here: https://php.watch/versions/8.2/dynamic-properties-deprecated
We should look at writing a sniff for this if possible.
Note: For some legacy code, we may choose to work around this using the AllowDynamicProperties attribute:
#[AllowDynamicProperties]
|
class User {
|
private int $uid;
|
}
|
|
$user = new User();
|
$user->name = 'Foo';
|
https://php.watch/versions/8.2/dynamic-properties-deprecated#AllowDynamicProperties
Other cases not affected
- stdClass
- classes with a magic __get and __set method
- is a clone of
-
MDL-76411 PHP 8.2: Dynamic Properties are deprecated
- Closed