1.2.1260. Undefined Properties¶
List of properties that are not explicitly defined in the class, its parents or traits.
It is possible to spot unidentified properties by using the PHP’s magic methods __get
and __set
. Even if the class doesn’t use magic methods, any call to an undefined property will be directed to those methods, and they can be used as a canary, warning that the code is missing a definition.
In PHP 8.2, undefined properties are reported as deprecated. They will become a Fatal Error in PHP 9.0.
<?php
class foo {
// property definition
private bar = 2;
function foofoo() {
// $this->bar is defined in the class
// $this->barbar is NOT defined in the class
return $this->bar + $this->barbar;
}
}
?>
See also Properties.
1.2.1260.2. Connex PHP features¶
1.2.1260.2.1. Suggestions¶
Add an explicit property definition, and give it
null
as a default value : this way, it behaves the same as undefined.Rename the property to one that exists already.
1.2.1260.2.2. Specs¶
Short name |
Classes/UndefinedProperty |
Rulesets |
All, Analyze, CE, CI-checks, Changed Behavior, CompatibilityPHP82 |
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Changed Behavior |
PHP 8.2 |
Precision |
Very high |
ClearPHP |
|
Examples |
|
Related rule |
|
Available in |