1.2.880. Only Variable Passed By Reference

When an argument is expected by reference, it is compulsory to provide a container. A container may be a variable, an array, a property or a static property.

This may be linted by PHP, when the function definition is in the same file as the function usage. This is silently linted if definition and usage are separated, if the call is dynamical or made as a method. This analysis currently covers functioncalls and static methodcalls, but omits methodcalls.

<?php

function foo(&$bar) { /**/ }

function &bar() { /**/ }

// This is not possible : strtolower() returns a value
foo(strtolower($string));

// This is valid : bar() returns a reference
foo(bar($string));

?>

See also Passing arguments by reference.

1.2.880.1. Suggestions

  • Store the previous result in a variable, and then call the function.

1.2.880.2. Specs

Short name

Functions/OnlyVariablePassedByReference

Rulesets

All, Analyze, IsExt, IsPHP, IsStub

Exakat since

0.11.3

PHP Version

All

Severity

Critical

Time To Fix

Slow (1 hour)

Precision

High

Features

reference, parameter

Examples

Dolphin, PhpIPAM

Available in

Entreprise Edition, Exakat Cloud