Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Using null as an array offset is deprecated, use an empty string instead

Description

Avoid using null as an array index. PHP converts it silently to an empty string anyway.

Example

<?php

$array = ['a' => 2];
$array[null] = 3;

?>

Alternatives

  • Replace the null with an empty string.
  • Check the value before using it as an array index.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See NullAsArrayOffset