Skip to content

Commit 26ed8d6

Browse files
Report unknown parameter for implicit variadic methods
1 parent acf7f97 commit 26ed8d6

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

src/Rules/FunctionCallParametersCheck.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,13 @@ private function processArguments(
562562
$originalParametersByName = [];
563563
$unusedParametersByName = [];
564564
$errors = [];
565+
$isNativelyVariadic = false;
565566
foreach ($parameters as $i => $parameter) {
566567
$parametersByName[$parameter->getName()] = $parameter;
567568
$originalParametersByName[$parameter->getName()] = $originalParameters[$i];
568569

569570
if ($parameter->isVariadic()) {
571+
$isNativelyVariadic = true;
570572
continue;
571573
}
572574

@@ -603,7 +605,7 @@ private function processArguments(
603605

604606
$parametersCount = count($parameters);
605607
if (
606-
!$parametersAcceptor->isVariadic()
608+
!$isNativelyVariadic
607609
|| $parametersCount <= 0
608610
|| $isBuiltin
609611
) {

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,20 @@ public function testBug4514(): void
534534
$this->analyse([__DIR__ . '/data/bug-4514.php'], []);
535535
}
536536

537+
public function testBug13719(): void
538+
{
539+
$this->analyse([__DIR__ . '/data/bug-13719.php'], [
540+
[
541+
'Unknown parameter $greetings in call to function non_variadic.',
542+
18,
543+
],
544+
[
545+
'Unknown parameter $greetings in call to function implicit_variadic.',
546+
25,
547+
],
548+
]);
549+
}
550+
537551
public function testBug4530(): void
538552
{
539553
$this->analyse([__DIR__ . '/data/bug-4530.php'], []);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php declare(strict_types = 1);
2+
3+
function non_variadic(string $name, ?string $greeting = null): void {
4+
var_dump($name);
5+
}
6+
7+
// Explicitly defined with variadic arguments.
8+
function explicit_variadic(string $name, ?string $greeting = null, string ...$args): void {
9+
var_dump($name);
10+
}
11+
12+
// Treated as variadic due to usage of `func_get_args()`.
13+
function implicit_variadic(string $name, ?string $greeting = null): void {
14+
var_dump(func_get_args());
15+
}
16+
17+
// PHPStan correctly detects the error ('greetings' vs 'greeting').
18+
non_variadic('my name', greetings: 'my greeting');
19+
20+
// PHPStan correctly doesn't report anything since the function
21+
// accepts variadic arguments and this is not an error.
22+
explicit_variadic('my name', greetings: 'my greeting');
23+
24+
// ISSUE: PHPStan should detect argument.unknown error here, but it doesn't.
25+
implicit_variadic('my name', greetings: 'my greeting');

0 commit comments

Comments
 (0)