1.2.568. Inconsistent Variable Usage

Those variables are used in various and inconsistent ways. It is difficult to understand if they are an array, an object or a scalar variable.

<?php

// $a is an array, then $b is a string.
$a = ['a', 'b', 'c'];
$b = implode('-', $a);

// $a is an array, then it is a string.
$a = ['a', 'b', 'c'];
$a = implode('-', $a);

?>

1.2.568.1. Suggestions

  • Keep one type for each variable. This keeps the code readable.

  • Give different names to variables with different types.

1.2.568.2. Specs

Short name

Variables/InconsistentUsage

Rulesets

All, Changed Behavior

Exakat since

1.6.9

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

High

Examples

WordPress

Available in

Entreprise Edition, Exakat Cloud