1.2.711. Mixed Keys In Array

Avoid mixing constants and literals in array keys.

When defining default values in arrays, it is recommended to avoid mixing constants and literals, as PHP may mistake them and overwrite the previous with the latter.

Either switch to a newer version of PHP (5.5 or newer), or make sure the resulting array hold the expected data. If not, reorder the definitions.

<?php

const ONE = 1;

$a = [ 1   => 2,
       ONE => 3];

?>

1.2.711.1. Suggestions

  • Use only literals or constants when building the array

1.2.711.2. Specs

Short name

Arrays/MixedKeys

Rulesets

All, CompatibilityPHP53, CompatibilityPHP54

Exakat since

0.8.4

PHP Version

With PHP 5.6 and more recent

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

High

Features

array

Available in

Entreprise Edition, Exakat Cloud