1.2.1011. Property Variable Confusion¶
Within a class, there is both a property and variables bearing the same name.
The property and the variable may easily be confused one for another and lead to a bug.
Sometimes, when the property is going to be replaced by the incoming argument, or data based on that argument, this naming schema is made on purpose, indicating that the current argument will eventually end up in the property. When the argument has the same name as the property, no warning is reported.
<?php
class Object {
private $x;
function SetData( ) {
$this->x = $x + 2;
}
}
?>
1.2.1011.1. Connex PHP features¶
1.2.1011.1.1. Suggestions¶
Use different names for the properties and variables
Adopt and apply a naming convention for variables and properties.
1.2.1011.1.2. Specs¶
Short name |
Structures/PropertyVariableConfusion |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Examples |
|
Available in |