1.2.1184. Swapped Arguments¶
Overwritten methods must be compatible, but argument names is not part of that compatibility.
Methods with the same name, in two classes of the same hierarchy, must be compatible for typehint, default value, reference. The name of the argument is not taken into account when checking such compatibility, at least until PHP 7.4. This analysis reports argument lists that differs in ordering. This analysis doesn’t report argument lists that also differs in argument names.
<?php
class x {
function foo($a, $b) {}
function bar($a, $b) {}
}
class y extends x {
// foo is compatible (identical) with the above class
function foo($a, $b) {}
// bar is compatible with the above class, yet, the argument might not receive what they expect.
function bar($b, $a) {}
}
?>
1.2.1184.1. Connex PHP features¶
1.2.1184.1.1. Suggestions¶
Make sure the names of the argument are in the same order in all classes and interfaces
1.2.1184.1.2. Specs¶
Short name |
Classes/SwappedArguments |
Rulesets |
|
Exakat since |
2.1.5 |
PHP Version |
All |
Severity |
Critical |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |