1.2.869. Null Or Boolean Arrays¶
Null, int, floats, booleans are valid with PHP array syntx. Yet, they only produces null
values. They also did not emits any warning until PHP 7.4.
Older code used to initialize variables as null, sometimes explictly, and then, use them as arrays. The current support for this syntax is for backward compatibility.
Illegal keys, such as another array, will also generate a NULL value, instead of a Fatal error.
<?php
// outputs NULL
var_dump(null[0]);
var_dump(null[[]]);
const MY_CONSTANT = true;
// outputs NULL
var_dump(MY_CONSTANT[10]);
?>
See also Null and True.
1.2.869.2. Connex PHP features¶
1.2.869.2.1. Suggestions¶
Avoid using the array syntax on null and boolean
Avoid using null and boolean on constant that are expecting arrays
1.2.869.2.2. Specs¶
Short name |
Arrays/NullBoolean |
Rulesets |
|
Exakat since |
1.8.6 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |