1.2.829. No Reference On Left Side

Do not use references as the right element in an assignation.

This is the case for most situations : addition, multiplication, bitshift, logical, power, concatenation. Note that PHP won’t compile the code if the operator is a short operator (+=, .=, etc.), nor if the & is on the right side of the operator.

<?php

$b = 2;
$c = 3;

$a = &$b + $c;
// $a === 2 === $b;

$a = $b + $c;
// $a === 5

?>

See also References Explained and Operator Precedence.

1.2.829.1. Specs

Short name

Structures/NoReferenceOnLeft

Rulesets

All, Analyze, CE, CI-checks

Exakat since

0.11.5

PHP Version

All

Severity

Critical

Time To Fix

Quick (30 mins)

Precision

Very high

Features

reference

Available in

Entreprise Edition, Community Edition, Exakat Cloud