Skip to content

Commit 744accc

Browse files
phpstan-botclaude
andcommitted
Add comprehensive tests for byRef in array literals
Address review feedback by adding tests for standalone `$b = [&$a]` patterns (not just call_user_func_array), including by-ref with keys and multiple by-ref items in a single array. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c617fd6 commit 744accc

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,43 @@ protected function listingAddWhereFilterAtable(array $filterValues, array &$wher
3232
foreach ($filterValues as $type => $value) {
3333
call_user_func_array(array($this, 'listingAddWhereFilterAtableDefault'), array(&$whereFilter, 'xxxx', $filters[$type], $value));
3434
}
35-
assertType('mixed', $whereFilter); // could be array<string>
35+
assertType('mixed', $whereFilter);
3636
}
3737
}
3838
}
39+
40+
/**
41+
* @param mixed $foo
42+
*/
43+
function foo($foo): void {}
44+
45+
function testByRefInArray(): void
46+
{
47+
$a = [];
48+
assertType('array{}', $a);
49+
50+
$b = [&$a];
51+
assertType('mixed', $a);
52+
53+
foo($b);
54+
assertType('mixed', $a);
55+
}
56+
57+
function testByRefInArrayWithKey(): void
58+
{
59+
$a = 'hello';
60+
assertType("'hello'", $a);
61+
62+
$b = ['key' => &$a];
63+
assertType('mixed', $a);
64+
}
65+
66+
function testMultipleByRefInArray(): void
67+
{
68+
$a = 1;
69+
$c = 'test';
70+
71+
$b = [&$a, 'normal', &$c];
72+
assertType('mixed', $a);
73+
assertType('mixed', $c);
74+
}

0 commit comments

Comments
 (0)