1.2.879. Only Variable For Reference

When a method is requesting an argument to be a reference, it cannot be called with a literal value.

The call must be made with a variable, or any assimilated data container : array, property or static property. Note that PHP may detect this error at linting time, if the method is defined after being called : at that point, PHP will only check the problem during execution. This is definitely the case for methods, compared to functions or static methods.

<?php

// This is not possible
foo(1,2);

// This is working
foo($a, $b);

function foo($a, &$b) {}

?>

See also Passing arguments by reference.

1.2.879.1. Suggestions

  • Put the literal value in a variable before calling the method.

  • Omit the arguments, when it won’t be used.

1.2.879.2. Specs

Short name

Functions/OnlyVariableForReference

Rulesets

All, Analyze, LintButWontExec

Exakat since

1.4.6

PHP Version

All

Severity

Critical

Time To Fix

Quick (30 mins)

Precision

Medium

Features

variable, reference

Note

This issue may lint but will not run

Available in

Entreprise Edition, Exakat Cloud