diff --git a/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php b/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php index b7f217f943..3c080b7642 100644 --- a/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php +++ b/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php @@ -151,7 +151,7 @@ private function getParameters(): array } $parameters[] = new PhpParameterFromParserNodeReflection( $parameter->var->name, - $isOptional, + $isOptional || $parameter->variadic, $this->realParameterTypes[$parameter->var->name], $this->phpDocParameterTypes[$parameter->var->name] ?? null, $parameter->byRef diff --git a/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php b/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php index fc1a1c2549..a76c28ca13 100644 --- a/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php +++ b/tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php @@ -5,6 +5,7 @@ use PHPStan\Php\PhpVersion; use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; +use const PHP_VERSION_ID; /** * @extends RuleTestCase @@ -313,4 +314,10 @@ public function testParle(int $phpVersion, string $contravariantMessage, string ]); } + public function testVariadicParameterIsAlwaysOptional(): void + { + $this->phpVersionId = PHP_VERSION_ID; + $this->analyse([__DIR__ . '/data/variadic-always-optional.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/variadic-always-optional.php b/tests/PHPStan/Rules/Methods/data/variadic-always-optional.php new file mode 100644 index 0000000000..24f26ced08 --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/variadic-always-optional.php @@ -0,0 +1,33 @@ +