问题描述
此代码产生错误:
/**
* @var EntityManagerInterface
*/
private EntityManagerInterface $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
parent::__construct();
}
我的 composer.json 使用
"php": ">=7.1.3",
我使用 Symfony 4.4,这是我工作的要求。
我在互联网上的某个地方发现这种类型的错误是由过时的 php 版本引起的,但我不确定在这种特定情况下是否是这种情况。我的问题是我是否可以编写不同的代码,或者我唯一的选择是使用更高的 php 版本?
解决方法
你不用放
EntityManagerInterface
在变量声明中。
所以,请更换
private EntityManagerInterface $entityManager;
通过
private $entityManager;
它的依赖注入已经添加在Constructor函数参数中:
public function __construct(EntityManagerInterface $entityManager)