1.2.1430. Written Only Variables

Those variables are being written, but never read. In this way, they are useless and should be removed, or be read at some point in the code.

When the variables are only written, it takes time to process them, while discarding their result without usage. Also, when those variables are built with a complex process, it makes it difficult to understand their point, and still create maintenance work.

<?php

// $a is used multiple times, but never read
$a = 'a';
$a .= 'b';

$b = 3;
//$b is actually read once
$a .= $b + 3;

?>

1.2.1430.1. Suggestions

  • Check that variables are written AND read in each context

  • Remove variables that are only read

  • Use the variable that are only read

1.2.1430.2. Specs

Short name

Variables/WrittenOnlyVariable

Rulesets

All, Analyze

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

Very high

Features

variable

ClearPHP

no-unused-variable

Examples

Dolibarr, SuiteCrm

Available in

Entreprise Edition, Exakat Cloud