PHP 7.1 可空类型的 Doctrine 代理问题

PHP 7.1 Doctrine proxy issue with nullable types

我正在使用 php7.1 的新功能,它允许 return 项目 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 自动创建的 class 的代码,我发现了这个:

<?php
// ...
public function getCreatedBy(): string
{

    $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCreatedBy', []);

    return parent::getCreatedBy();
}

如您所见,类型不可为空。

有人可以帮助我吗?谢谢

我通过从 doctrine/doctrine-common 库的 2.6 版升级到 2.8 版解决了这个问题