1.2.354. Different Constructors¶
PHP allows different signatures for constructors. This is a legacy feature.
Only constructors are allowed to have different signatures : all other methods must be compatible with the parent methods.
<?php
class x {
function __construct($a) {
}
}
class y extends x {
function __construct($a, $b) {
$this->b = $a;
parent::__construct($a);
}
}
?>
1.2.354.1. Suggestions¶
Synchronize the methods signatures
Make use of named constructors to have different signatures when building objects
1.2.354.2. Specs¶
Short name |
Classes/IncompatibleConstructor |
Rulesets |
|
Exakat since |
2.5.2 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Medium |
Available in |