TYPO3 EventDispatcherInterface

98 Views Asked by At

I try to inject the $eventDispatcher in my Repository

private EventDispatcherInterface $eventDispatcher;

public function injectEventDispatcher(EventDispatcherInterface $eventDispatcher): void
    {
        $this->eventDispatcher = $eventDispatcher;
    }

But since PHP 7.4 you have to be initialized. But I cant initialize the EventDispatcherInterface and get this error : Typed property $eventDispatcher must not be accessed before initialization

How can I initialize the eventDispatcher? Thanks.

1

There are 1 best solutions below

0
Julian Hofmann On

Maybe, switching to Constructor Injection can solve this:

public function __construct(EventDispatcherInterface $eventDispatcher)
{
    $this->eventDispatcher = $eventDispatcher;
}