website/errors/parameter.notVariadic.md
<?php declare(strict_types = 1);
interface Handler
{
public function handle(string ...$args): void;
}
class MyHandler implements Handler
{
public function handle(string $args): void
{
}
}
A method parameter is declared as non-variadic, but the corresponding parameter in the parent method or interface is variadic. This violates the Liskov Substitution Principle -- code that calls the parent method with multiple arguments would fail when the overriding method is called instead.
In the example above, Handler::handle() accepts any number of string arguments, but MyHandler::handle() accepts only one.
Make the parameter variadic to match the parent declaration:
class MyHandler implements Handler
{
- public function handle(string $args): void
+ public function handle(string ...$args): void
{
}
}