Inspection S1185 for PHP (Overriding methods should do more than simply call the same method in super class) generates false positive when the subclass has different type hints.
Extra PHP detail: A __construct() is even allowed to have a completely different signature.
Example code:
class A
{
public function __construct(FooInterface $arg1)
{
// init..
}
}
class DefaultA extends A
{
public function __construct(FooConcrete $arg1)
{
parent::__construct($arg1);
}
}
In the given example, the constructor gets another type hinted arg. This is allowed and even recommended code in most popular frameworks! For some DI autowiring frameworks (for instance, Laravel), it is The Way to automatically get the proper dependency injected.
So with regards to this rule:
- For __construct(), a type hint may change and that’s sufficient reason to overload the method (given example)
- For __construct(), it’s even true that the amount of arguments may even change AND that the type hints don’t need to follow the liskov substitution principle (i.e. don’t even need to be the type or a wider type).
- For any other method, replacing a type hint with a broader type hint is allowed (liskov substitution principle).