Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Rules/FunctionCallParametersCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,13 @@ private function processArguments(
$originalParametersByName = [];
$unusedParametersByName = [];
$errors = [];
$isNativelyVariadic = false;
foreach ($parameters as $i => $parameter) {
$parametersByName[$parameter->getName()] = $parameter;
$originalParametersByName[$parameter->getName()] = $originalParameters[$i];

if ($parameter->isVariadic()) {
$isNativelyVariadic = true;
continue;
}

Expand Down Expand Up @@ -603,7 +605,7 @@ private function processArguments(

$parametersCount = count($parameters);
if (
!$parametersAcceptor->isVariadic()
!$isNativelyVariadic
|| $parametersCount <= 0
|| $isBuiltin
) {
Expand Down
15 changes: 15 additions & 0 deletions tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,21 @@ public function testBug4514(): void
$this->analyse([__DIR__ . '/data/bug-4514.php'], []);
}

#[RequiresPhp('>= 8.0')]
public function testBug13719(): void
{
$this->analyse([__DIR__ . '/data/bug-13719.php'], [
[
'Unknown parameter $greetings in call to function non_variadic.',
18,
],
[
'Unknown parameter $greetings in call to function implicit_variadic.',
25,
],
]);
}

public function testBug4530(): void
{
$this->analyse([__DIR__ . '/data/bug-4530.php'], []);
Expand Down
25 changes: 25 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-13719.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types = 1);

function non_variadic(string $name, ?string $greeting = null): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add namespace Bug13719 to this file

var_dump($name);
}

// Explicitly defined with variadic arguments.
function explicit_variadic(string $name, ?string $greeting = null, string ...$args): void {
var_dump($name);
}

// Treated as variadic due to usage of `func_get_args()`.
function implicit_variadic(string $name, ?string $greeting = null): void {
var_dump(func_get_args());
}

// PHPStan correctly detects the error ('greetings' vs 'greeting').
non_variadic('my name', greetings: 'my greeting');

// PHPStan correctly doesn't report anything since the function
// accepts variadic arguments and this is not an error.
explicit_variadic('my name', greetings: 'my greeting');

// ISSUE: PHPStan should detect argument.unknown error here, but it doesn't.
implicit_variadic('my name', greetings: 'my greeting');
Loading