1.2.47. Array() / [ ] Consistence¶
array() or [ ] is the favorite.
array() and [ ] have the same functional use.
The analyzed code has less than 10% of one of them : for consistency reasons, it is recommended to make them all the same.
It happens that array() or [] are used depending on coding style and files. One file may be consistently using array(), while the others are all using [].
The only drawback to use [] over array() is backward incompatibility.
<?php
$a = array(1, 2);
$b = array(array(3, 4), array(5, 6));
$c = array(array(array(7, 8), array(9, 10)), array(11, 12), array(13, 14)));
// be consistent
$d = [1, 3];
?>
Name |
Default |
Type |
Description |
array_ratio |
10 |
integer |
Percentage of arrays in one of the syntaxes, to trigger the other syntax as a violation. |
1.2.47.1. Connex PHP features¶
1.2.47.1.1. Suggestions¶
Use one syntax consistently.
1.2.47.1.2. Specs¶
Short name |
Arrays/ArrayBracketConsistence |
Rulesets |
|
Exakat since |
0.8.9 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
High |
Available in |