Doctrine php7 +类型提示,代理声明错误

hve*_*ous 5 symfony doctrine-orm php-7 php-7.1

我经常遇到这个奇怪的错误

  Warning: Declaration of Proxies\__CG__\AppBundle\Entity\MyEntity::setName(string $name): 
  AppBundle\Entity\MyEntity should be compatible with AppBundle\Entity\MyEntity::setName(?string $name): 
  AppBundle\Entity\MyEntity
Run Code Online (Sandbox Code Playgroud)

为什么发生这种情况?为什么我没有

public function setName(?string $name): self
{
    $this->name = $name;

    return $this;
}
Run Code Online (Sandbox Code Playgroud)

作为我的二传手?如果我删除'?',它可以工作,但我确实需要它用于其他目的

Tob*_* Xy 5

正如我在评论中已提到的:根据此问题,如果您使用可选参数类型提示,则旧版本的doctrine/common(特别是早于2.7.1)可能在创建匹配代理类时遇到问题.

更新doctrine/common似乎解决了这个问题.