1.2.817. No Null For Index

Avoid using null value as an index in an array. PHP actually cast it to the empty string. This means that later, it might be impossible to find the null in the list of keys.

<?php

$a = [];
$a[null] = 1;

print_r(array_keys($a));
// [''] empty string

?>

1.2.817.1. Suggestions

  • Always checks for null values. Given it then a valid value.

1.2.817.2. Specs

Short name

Structures/NoNullForIndex

Rulesets

All, Analyze, Changed Behavior

Exakat since

2.5.3

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Medium

Available in

Entreprise Edition, Exakat Cloud