1.2.1403. Useless Referenced Argument¶
The argument has a reference, and is only used for reading.
This is probably a development artefact that was forgotten. It is better to remove it.
This analysis also applies to foreach() loops, that declare the blind variable as reference, then use the variable as an object, accessing properties and methods. When a variable contains an object, there is no need to declare a reference : it is a reference automatically.
<?php
function foo($a, &$b, &$c) {
// $c is passed by reference, but only read. The reference is useless.
$b = $c + $a;
// The reference is useful for $b
}
foreach ($array as &$element) {
$element->method();
}
?>
See also Objects and references.
1.2.1403.1. Connex PHP features¶
1.2.1403.1.1. Suggestions¶
Remove the useless & from the argument
Make an actual use of the argument before the end of the method
1.2.1403.1.2. Specs¶
Short name |
Functions/UselessReferenceArgument |
Rulesets |
|
Exakat since |
1.1.3 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
High |
Examples |
|
Available in |