1.2.685. Method Property Confusion¶
There might be confusion between a property and a method when they bear the same name. While it is a valid PHP syntax, using the same name for properties and methods leads to possible confusion in the code.
<?php
class x {
private $query = 1;
function query() : void {}
function foo() {
// The property is useless : it may be a call to the method, in fact
$this->query;
// The method call returns nothing : PHP replaces it with NULL.
$c = $this->query();
}
}
?>
1.2.685.1. Suggestions¶
Change the name : either the property, or the method
1.2.685.2. Specs¶
Short name |
Classes/MethodPropertyConfusion |
Rulesets |
|
Exakat since |
2.5.0 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |