diff --git a/src/Rules/FunctionDefinitionCheck.php b/src/Rules/FunctionDefinitionCheck.php index 1c9a37df29..c12b527ef1 100644 --- a/src/Rules/FunctionDefinitionCheck.php +++ b/src/Rules/FunctionDefinitionCheck.php @@ -321,7 +321,7 @@ private function checkRequiredParameterAfterOptional(array $parameterNodes): arr throw new \PHPStan\ShouldNotHappenException(); } $parameterName = $parameterNode->var->name; - if ($optionalParameter !== null && $parameterNode->default === null) { + if ($optionalParameter !== null && $parameterNode->default === null && !$parameterNode->variadic) { $errors[] = RuleErrorBuilder::message(sprintf('Deprecated in PHP 8.0: Required parameter $%s follows optional parameter $%s.', $parameterName, $optionalParameter))->line($parameterNode->getStartLine())->nonIgnorable()->build(); continue; } diff --git a/tests/PHPStan/Rules/Functions/data/required-parameter-after-optional.php b/tests/PHPStan/Rules/Functions/data/required-parameter-after-optional.php index 4e4e1b6a49..373a441903 100644 --- a/tests/PHPStan/Rules/Functions/data/required-parameter-after-optional.php +++ b/tests/PHPStan/Rules/Functions/data/required-parameter-after-optional.php @@ -18,3 +18,7 @@ function doBaz(int $foo = 1, $bar): void // not OK function doLorem(bool $foo = true, $bar): void // not OK { } + +function doIpsum(bool $foo = true, ...$bar): void // OK +{ +}