1.2.1393. 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.1393.1. Suggestions

  • Remove the useless & from the argument

  • Make an actual use of the argument before the end of the method

1.2.1393.2. Specs

Short name

Functions/UselessReferenceArgument

Rulesets

All, Analyze, Changed Behavior

Exakat since

1.1.3

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

High

Features

reference, argument

Examples

Woocommerce, Magento

Available in

Entreprise Edition, Exakat Cloud