1.2.371. Don’t Read And Write In One Expression

Avoid giving value and using it at the same time, in one expression. This is an undefined behavior of PHP, and may change without warning.

One of those changes happens between PHP 7.2 and 7.3 :

<?php

$arr = [1];
$ref =& $arr[0];
var_dump($arr[0] + ($arr[0] = 2));
// PHP 7.2: int(4)
// PHP 7.3: int(3)

?>

See also UPGRADING 7.3.

1.2.371.1. Suggestions

  • Split the expression in two separate expressions

1.2.371.2. Specs

Short name

Structures/DontReadAndWriteInOneExpression

Rulesets

All, Analyze, CE, CompatibilityPHP73, CompatibilityPHP74

Exakat since

1.4.9

PHP Version

All

Severity

Critical

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Community Edition, Exakat Cloud