[英]TYPO3 EventDispatcherInterface
I try to inject the $eventDispatcher
in my Repository我尝试在我的存储库中注入
$eventDispatcher
private EventDispatcherInterface $eventDispatcher;
public function injectEventDispatcher(EventDispatcherInterface $eventDispatcher): void
{
$this->eventDispatcher = $eventDispatcher;
}
But since PHP 7.4 you have to be initialized.但是由于 PHP 7.4 你必须进行初始化。 But I cant initialize the EventDispatcherInterface and get this error: Typed property $eventDispatcher must not be accessed before initialization
但是我无法初始化 EventDispatcherInterface 并收到此错误:在初始化之前不得访问类型化属性 $eventDispatcher
How can I initialize the eventDispatcher?如何初始化 eventDispatcher? Thanks.
谢谢。
Maybe, switching to Constructor Injection can solve this:也许,切换到构造函数注入可以解决这个问题:
public function __construct(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.