Skip to content

Commit 2d7ce79

Browse files
phpstan-botclaude
andcommitted
Use @param-out type for call_user_func_array by-reference args
When a by-reference parameter has a @param-out PHPDoc, use that type instead of the @param type when updating scope after call_user_func_array. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 50749d7 commit 2d7ce79

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/Analyser/ExprHandler/FuncCallHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use PHPStan\Node\Expr\PossiblyImpureCallExpr;
3333
use PHPStan\Node\Expr\TypeExpr;
3434
use PHPStan\Reflection\Callables\CallableParametersAcceptor;
35+
use PHPStan\Reflection\ExtendedParameterReflection;
3536
use PHPStan\Reflection\Callables\SimpleImpurePoint;
3637
use PHPStan\Reflection\Callables\SimpleThrowPoint;
3738
use PHPStan\Reflection\FunctionReflection;
@@ -238,7 +239,9 @@ public function processExpr(NodeScopeResolver $nodeScopeResolver, Stmt $stmt, Ex
238239
continue;
239240
}
240241

241-
$byRefType = $innerParameter->getType();
242+
$byRefType = $innerParameter instanceof ExtendedParameterReflection && $innerParameter->getOutType() !== null
243+
? $innerParameter->getOutType()
244+
: $innerParameter->getType();
242245
$scope = $nodeScopeResolver->processVirtualAssign(
243246
$scope,
244247
$storage,

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,20 @@ protected function listingAddWhereFilterAtable(array $filterValues, array &$wher
3535
assertType('array<string>', $whereFilter);
3636
}
3737
}
38+
39+
/**
40+
* @param array<mixed> $items
41+
* @param-out list<int> $items
42+
*/
43+
protected function processWithParamOut(array &$items): void
44+
{
45+
$items = [1, 2, 3];
46+
}
47+
48+
protected function testParamOut(): void
49+
{
50+
$items = [];
51+
call_user_func_array([$this, 'processWithParamOut'], [&$items]);
52+
assertType('list<int>', $items);
53+
}
3854
}

0 commit comments

Comments
 (0)