Skip to content

Commit da76a4b

Browse files
phpstan-botclaude
andcommitted
Add tests for union callback types in call_user_func_array by-ref handling
Tests cover: - Union of string method names ('method1'|'method2') - Union of constant array callbacks - Mixed union of string and array callback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7e864e4 commit da76a4b

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,43 @@ protected function testParamOut(): void
5151
call_user_func_array([$this, 'processWithParamOut'], [&$items]);
5252
assertType('list<int>', $items);
5353
}
54+
55+
/**
56+
* @param array<mixed> $items
57+
* @param-out list<string> $items
58+
*/
59+
protected function processWithParamOutStrings(array &$items): void
60+
{
61+
$items = ['a', 'b'];
62+
}
63+
64+
/**
65+
* @param 'processWithParamOut'|'processWithParamOutStrings' $method
66+
*/
67+
protected function testUnionStringCallbacks(string $method): void
68+
{
69+
$items = [];
70+
call_user_func_array([$this, $method], [&$items]);
71+
assertType('list<int|string>', $items);
72+
}
73+
74+
/**
75+
* @param array{$this, 'processWithParamOut'}|array{$this, 'processWithParamOutStrings'} $callback
76+
*/
77+
protected function testUnionArrayCallbacks(array $callback): void
78+
{
79+
$items = [];
80+
call_user_func_array($callback, [&$items]);
81+
assertType('list<int|string>', $items);
82+
}
83+
84+
/**
85+
* @param 'processWithParamOut'|array{$this, 'processWithParamOutStrings'} $callback
86+
*/
87+
protected function testMixedUnionCallback($callback): void
88+
{
89+
$items = [];
90+
call_user_func_array($callback, [&$items]);
91+
assertType('array{}', $items);
92+
}
5493
}

0 commit comments

Comments
 (0)