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

Negative Automatic Index From Empty Array

When starting from an empty array and assigning an initial negative integer index, PHP used to continue assigning indices with 0, instead of the following negative number. It is fixed in PHP 8.3.

PHP code

<?php

$array = [];
$array[-2] = 'a';
$array[] = 'b';

print_r($array);

?>

Before

Array
(
    [-2] => a
    [0] => b
)

After

Array
(
    [-2] => a
    [-1] => b
)

PHP version change

This behavior changed in 8.3.

Extension

© 2023-2026, Damien Seguy - Exakat