当我尝试覆盖无类型标识符时,它在我的交互式shell(PHP 5.6)中工作正常:
php -a
Interactive shell
php > class A { public function me($me) { var_dump($me); } }
php > class B extends A { public function me(\One $me) { parent::me($me); } }
php > class One { } // Yes, somehow this was legal.
php > $a = new A();
php > $a->me('hi');
string(2) "hi"
php > $b = new B();
php > $b->me(new One());
object(One)#3 (0) {
}
php > $b->me('hi');
PHP Catchable fatal error: Argument 1 passed to B::me() must be an instance of One, string given, called in php shell code on line 1 and defined in php shell code on line 1
Catchable fatal error: Argument 1 passed to B::me() must be an instance of One, string given, called in php shell code on line 1 and defined in php shell code on line 1
但是在我的5.3服务器上,它给了我:
PHP Fatal error: Declaration of B::me() must be compatible with that of A::me() in B.php on line 20
我无法从Google或PHP文档中找到有关此差异的任何信息。