Skip to content

Commit 15a85d8

Browse files
phpstan-botclaude
andcommitted
Add test for non-empty string-key array to guard initializedEmpty condition
This test would fail on PHP 8.0-8.2 if initializedEmpty was set unconditionally in createFromConstantArray. With only string keys, max(nextAutoIndexes) is 0 but there are no negative int keys, so initializedEmpty should stay false, allowing negative keys to update the auto-index. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 94e9657 commit 15a85d8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/PHPStan/Analyser/nsrt/bug-10862-php80.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ function () {
2121

2222
assertType("array{-10: 'a', -5: 'b', -4: 'c'}", $a);
2323
};
24+
25+
// Non-empty string-key array: negative key should update auto-index
26+
function () {
27+
$a = ['foo' => 'bar'];
28+
$a[-5] = 'x';
29+
$a[] = 'y';
30+
31+
assertType("array{foo: 'bar', -5: 'x', -4: 'y'}", $a);
32+
};

0 commit comments

Comments
 (0)