website/errors/parameter.variadic.md
<?php declare(strict_types = 1);
class Foo
{
public function doFoo(int $i, string $j): void
{
}
}
class Bar extends Foo
{
public function doFoo(int ...$i): void
{
}
}
The overriding method declares a parameter as variadic (...), but the corresponding parameter in the parent method is not variadic. In the example above, Bar::doFoo() declares ...$i as variadic, while Foo::doFoo() declares $i as a regular parameter.
This changes the method signature in a way that is incompatible with the parent. A variadic parameter accepts zero or more arguments, while the parent method expects a fixed number of arguments at specific positions.
Match the parent method's parameter list instead of using a variadic parameter:
class Bar extends Foo
{
- public function doFoo(int ...$i): void
+ public function doFoo(int $i, string $j): void
{
}
}