1.2.46. Array With String Initialization¶
It used to be possible to initialize a variable with an string, and use it as an array. It is not the case anymore in PHP 7.1.
<?php
// Initialize arrays with array()
$a = array();
$a[3] = "4";
// Don't start with a string
$a = '';
$a[3] = "4";
print $a;
// Don't start with a string
if (is_numeric($a)) {
$a[] = $a;
}
?>
1.2.46.2. Connex PHP features¶
1.2.46.2.1. Suggestions¶
Always initialize arrays with an empty array(), not a string.
1.2.46.2.2. Specs¶
Short name |
Arrays/StringInitialization |
Rulesets |
|
Exakat since |
1.6.5 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |