0

此代码产生错误:

     /**
     * @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 版本?

4

1 回答 1

1

你不需要把

EntityManagerInterface

在变量声明中。

所以,请更换

private EntityManagerInterface $entityManager;

经过

private $entityManager;

它的依赖注入已经添加在构造函数参数中:

public function __construct(EntityManagerInterface $entityManager)

于 2021-03-30T11:04:41.720 回答