这就是我所拥有的:
<?php
abstract class BasePlayer {
...
}
class Player extends BasePlayer {
...
}
abstract class BaseRoom {
abstract public function joinPlayer(BasePlayer $player);
}
class Room extends BaseRoom {
public function joinPlayer(Player $player) {
...
}
}
长话短说,在声明中我使用了一个抽象(通用)类,而在实现中我使用了这个抽象的子类。不幸的是,它抛出
PHP Fatal error: Declaration of Room::joinPlayer() must be compatible with BaseRoom::joinPlayer(BasePlayer $player)
如果您对此问题提出任何建议,我将非常感激。