This message means that there are certain possible method calls that may not work at run time. Suppose you have
class A { public function foo($a = 1) {;}} class B extends A { public function foo($a) {;}} function bar(A $a) {$a->foo();}
The compiler only checks the call to $ a-> foo () for the requirements of A :: foo (), which does not require any parameters. However, $ a may be an object of class B that requires a parameter, and therefore the call will fail at runtime.
This, however, can never fail and does not cause an error.
class A { public function foo($a) {;}} class B extends A { public function foo($a = 1) {;}} function bar(A $a) {$a->foo();}
Thus, no method can have more required parameters than its parent method.
The same message is also generated when type hints do not match, but in this case PHP is even more restrictive. This gives an error:
class A { public function foo(StdClass $a) {;}} class B extends A { public function foo($a) {;}}
how it does:
class A { public function foo($a) {;}} class B extends A { public function foo(StdClass $a) {;}}
This seems more restrictive than it should be, and I guess this is due to internal functions.
Differences in visibility cause a different error, but for the same main reason. No method can be less noticeable than its parent method.
ldrut Feb 11 2018-12-12T00: 00Z
source share