1.2.1198. Too Many Array Dimensions¶
This analysis reports when arrays have too many dimensions. This happens when arrays are too deeply nested inside other arrays.
PHP has no nesting limit, and accepts any number of of dimensions. This is usually very memory hungry, and could be better replaced with classes.
The default threshold for this rule is 3 (see examples above).
<?php
$a = array(); // level 1;
$a[1] = array(); // level 2
$a[1][2] = array(); // level 3 : still valid by default
$a[1][2][3] = array(); // level 4
?>
Name |
Default |
Type |
Description |
maxDimensions |
3 |
integer |
Number of valid dimensions in an array. |
1.2.1198.1. Suggestions¶
Replace the arrays by classes
Flatten the structure of the arrays
1.2.1198.2. Specs¶
Short name |
Arrays/TooManyDimensions |
Rulesets |
|
Exakat since |
1.9.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Features |
multidimensional-array |
Available in |