Description
The following code:
<?php
$a = array(123 => 123);
unset($a[123]);
$b = array_keys($a);
$b[] = 42;
var_dump($b);
Resulted in this output:
array(1) {
[124]=>
int(42)
}
But I expected this output instead:
array(1) {
[0]=>
int(42)
}
The behavior changed during a patch version update: https://3v4l.org/KR2JQ#veol
This only happens when array_keys() is provided with an empty array that previously contained some elements.
PHP Version
PHP 8.4.25 (cli) (built: Aug 28 2026 07:36:03) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.25, Copyright (c) Zend Technologies
with Zend OPcache v8.4.25, Copyright (c), by Zend Technologies
Operating System
No response
Description
The following code:
Resulted in this output:
But I expected this output instead:
The behavior changed during a patch version update: https://3v4l.org/KR2JQ#veol
This only happens when
array_keys()is provided with an empty array that previously contained some elements.PHP Version
Operating System
No response