1.2.35. Ambiguous Visibilities¶
The properties have the same name, but have different visibilities, across different classes.
While it is legit to have a property with the same name in different classes, it may easily lead to confusion. As soon as the context is need to understand if the property is accessible or not, the readability suffers.
It is recommended to handle the same properties in the same way across classes, even when the classes are not related.
<?php
class person {
public $name;
private $address;
}
class gangster {
private $name;
public $nickname;
private $address;
}
$someone = Human::load(123);
echo 'Hello, '.$someone->name;
?>
1.2.35.1. Connex PHP features¶
1.2.35.1.1. Suggestions¶
Sync visibilities for both properties, in the different classes
Use different names for properties with different usages
1.2.35.1.2. Specs¶
Short name |
Classes/AmbiguousVisibilities |
Rulesets |
|
Exakat since |
1.3.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Examples |
|
Related rule |
|
Available in |