Skip to content

Commit 8b0088a

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-23576: array_keys() on an empty array returns a non-zero next index (#23577)
2 parents 810a9e5 + 752c9ff commit 8b0088a

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ PHP NEWS
9191
INT_MAX instead of truncating it. (marc-mabe)
9292
. Fixed GH-23338 (fsockopen()/pfsockopen() ValueError reported wrong
9393
argument number for $timeout). (lacatoire)
94+
. Fixed bug GH-23576 (Next index for array returned from array_keys() is
95+
wrong). (Lazizbek Ergashev)
9496

9597
- SimpleXML:
9698
. Fixed writing to a dimension of the object returned by attributes() not

ext/standard/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4406,7 +4406,7 @@ PHP_FUNCTION(array_keys)
44064406

44074407
/* Base case: empty input */
44084408
if (!elem_count) {
4409-
RETURN_COPY(input);
4409+
RETURN_EMPTY_ARRAY();
44104410
}
44114411

44124412
/* Initialize return array */
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
--TEST--
2+
GH-23576 (Next index for array returned from array_keys() is wrong)
3+
--FILE--
4+
<?php
5+
$a = [123 => 123];
6+
unset($a[123]);
7+
8+
$b = array_keys($a);
9+
$b[] = 42;
10+
var_dump($b);
11+
12+
$c = array_keys($a, 123);
13+
$c[] = 42;
14+
var_dump($c);
15+
16+
$d = array_keys($a, 123, true);
17+
$d[] = 42;
18+
var_dump($d);
19+
20+
$e = [];
21+
22+
$f = array_keys($e);
23+
$f[] = 42;
24+
var_dump($f);
25+
26+
$g = array_keys($e, 123);
27+
$g[] = 42;
28+
var_dump($g);
29+
30+
$h = array_keys($e, 123, true);
31+
$h[] = 42;
32+
var_dump($h);
33+
?>
34+
--EXPECT--
35+
array(1) {
36+
[0]=>
37+
int(42)
38+
}
39+
array(1) {
40+
[0]=>
41+
int(42)
42+
}
43+
array(1) {
44+
[0]=>
45+
int(42)
46+
}
47+
array(1) {
48+
[0]=>
49+
int(42)
50+
}
51+
array(1) {
52+
[0]=>
53+
int(42)
54+
}
55+
array(1) {
56+
[0]=>
57+
int(42)
58+
}

0 commit comments

Comments
 (0)