I have these two interfaces:
interface Observer
{
public function notify(Observable $observable, ...$args);
}
interface Observable
{
public static function register(Observer $observer);
public function notifyObservers();
}
And here is what I am trying to implement:
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...
}
}
Event is an Observable and EventHandler is an Observer, right?
So why php considers these implementation incompatible with their respective interfaces?
A simple test of what I meant by "compatible":
class CreateEvent extends Event {}
$createEventObj = new CreateEvent();
if ($createEventObj instanceof Observable) {
echo 'Compatible';
} else {
echo 'Incompatible';
}