【发布时间】:2017-09-28 10:07:09
【问题描述】:
我正在使用 php7.1 的新功能,它允许在项目 Symfony 3 上返回可为空的类型,但是在实体中使用它时遇到问题:
<?php
// ....
public function getCreatedBy(): ?string
{
return $this->createdBy;
}
当我使用这个功能时,我遇到了这个错误:
Type error: Return value of
Proxies\\__CG__\\NS\\ModulesBundle\\Entity\\Account::getCreatedBy()
must be of the type string, null returned
我查看了使用 Symfony 自动创建的类的代码,发现:
<?php
// ...
public function getCreatedBy(): string
{
$this->__initializer__ && $this->__initializer__->__invoke($this, 'getCreatedBy', []);
return parent::getCreatedBy();
}
如您所见,该类型不可为空。
有人可以帮助我吗?谢谢
【问题讨论】:
-
你清除缓存了吗?
-
是的,我清除了缓存
-
这是与 Doctrine 相关的问题,与 Symfony 本身无关。
-
是的,我通过将 lib 教义/doctrine-common 升级到 2.8 版解决了这个问题