如何解决ParseError:语法错误,意外的“EntityManagerInterface”T_STRING,需要函数T_FUNCTION或常量T_CONST
此代码产生错误:
/**
* @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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。