Such errors as were provided with PHP 5.0 and the very appearance of type hinting in PHP remained.
The only thing is that first the E_STRICT level E_STRICT not included in E_ALL and had to be specified explicitly, then, starting with PHP 5.4, it began to enter. After that, in PHP 7.0, errors from E_STRICT redistributed to other types of errors . The community agreed on the opinion that breach of the base class contract is a bad thing and should be noticeable, so the error was assigned the E_WARNING level. It is a pity, of course, that in 2004 they changed the initial implementation of this check, where this type of error was generated by E_COMPILE_ERROR .
Well, who is to blame, that neither you nor your project colleagues for so many years have ever listened to what the developer’s closest friend says - the compiler of your programming language.
What to do next:
- to correct. It will take a long time to refactor such blunders, and this indicates the overall quality of the code. Surely not even
E_NOTICE included. - ignore errors in the log
- hide your head in the sand and hide mistakes
Settings "such varnings deduce, and such not" - fortunately not.
The specific error described in the question can be transferred to runtime. In the base class, one parameter is specified without a type with a default value, the child class may take additional optional method arguments, and this is not a violation of the class contract.
class ExampleParent { public function dosome ($c = null) {} } class Example extends ExampleParent { /* * переименовываем существующий метод * в будущем коде используем его вместо dosome */ public function readablenamemethod(Foo $a, Bar $b, $c = 0) { } /** * на его место ставим заглушку и вручную проверяем аргументы на совместимость * @deprecated */ public function dosome ($a = null, $b = null, $c = null) { if ($a instanceof Foo and $b instanceof Bar) { // на такой набор параметров мы хотим реагировать return $this->readablenamemethod($a, $b, $c ?? 0); } throw new \InvalidArgumentException('wrong arguments given'); } }
If the base class requires some class argument, and the child in this place wants a scalar or a completely different object - then change the contract of the base class with type hinting to check in runtime.