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.
Maybe, switching to Constructor Injection can solve this:
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.