나는이 두 가지 인터페이스를 가지고 : 여기이 구현이 PHP의 인터페이스와 호환되지 않는 이유는 무엇입니까?
interface Observer
{
public function notify(Observable $observable, ...$args);
}
interface Observable
{
public static function register(Observer $observer);
public function notifyObservers();
}
그리고 것은 내가 구현하기 위해 노력하고 무엇 :
abstract class EventHandler implements Observer
{
abstract public function notify(Event $event, ...$args);
}
abstract class Event implements Observable
{
private static $handlers = [];
public static function register(EventHandler $handler)
{
self::$handlers []= $handler;
}
public function notifyObservers()
{
//notify loop here...
}
}
이벤트이이 관찰자 인 관찰 가능한 및 이벤트 핸들러이다, 권리?
왜 php는 이러한 구현이 각각의 인터페이스와 호환되지 않는 것으로 간주합니까?
나는 "호환"무슨 뜻인지의 간단한 테스트 :
class CreateEvent extends Event {}
$createEventObj = new CreateEvent();
if ($createEventObj instanceof Observable) {
echo 'Compatible';
} else {
echo 'Incompatible';
}
런타임 오류가 발생합니까? – YvesLeBorg
@YvesLeBorg 예, Event :: register' 및'EventHandler :: notify' 메서드에서 "imcompatible declaration"치명적인 오류가 계속 발생합니다. – CarlosCarucce