Skip to content

Commit 01977ee

Browse files
phpstan-botclaude
andcommitted
Add test for multi-scalar key values in array by-ref tracking
When a key has multiple possible scalar values (e.g. bool maps to 0 or 1), the reference is tracked using the original key expression, so assignments to either possible index correctly propagate through the reference. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f0ba82a commit 01977ee

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

tests/PHPStan/Analyser/nsrt/bug-14333.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ function testNested(): void
6868
assertType('2', $a);
6969
}
7070

71+
function testMultipleScalarKeyValues(bool $key): void
72+
{
73+
$a = 1;
74+
75+
// $key is true|false, so it maps to int 1 or 0 — two possible scalar values
76+
$b = [$key => &$a];
77+
assertType('1', $a);
78+
79+
// $key could be 0 (false) so $b[0] = 2 might update $a through the reference
80+
$b[0] = 2;
81+
assertType('1|2', $a);
82+
83+
// $key could be 1 (true) so $b[1] = 3 might also update $a
84+
$b[1] = 3;
85+
assertType('1|2|3', $a);
86+
}
87+
7188
function foo(array &$a): void {}
7289

7390
function testFunctionCall() {

0 commit comments

Comments
 (0)