1.2.1065. Same Name For Property And Method¶
A property and a method have the same name. While it is a valid naming scheme with PHP, it may lead to confusion while codeing.
Such naming collision may appear with words that are the same as a verb (for method) and as a noun (for property). For example, in English : query, work, debug, run, process, rain, polish, paint, etc,.
It may also happen during the life cycle of the class, as it is extended with new methods and properties, and little care is give to semantic meaning of the names, beyond the task at hand. It is recommended to avoid those collisions, and keep properties and methods named distinctly.
That problem do not happen to constants, which are mostly written uppercase. This rule is case-insensitive.
<?php
class x {
public $foo;
function foo() {}
}
$x = new X:
$x->p = $x->foo();
?>
See also Words That Are Both Nouns And Verbs.
1.2.1065.1. Suggestions¶
Fix any spelling in the names
Rename the property or the method
1.2.1065.2. Specs¶
Short name |
Classes/PropertyMethodSameName |
Rulesets |
|
Exakat since |
2.4.5 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |