2017-08-17 72 views
3

的,我经常收到这种奇怪的错误主义PHP7 +类型提示,声明代理错误

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 
地球上

这究竟是为什么?为什么我没有

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

    return $this; 
} 

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

+0

通常这可以通过清除symfony缓存来解决。你已经这样做了吗? –

+0

您是否尝试过使用'public function setName(string $ name = null):self'? – yceruto

+0

@TobiasXy,是的,我尝试使用symfony命令并删除缓存目录。它不利于这种情况。 – user7808407

回答

2

正如我在评论中提到的:根据this issue旧版本的doctrine/common(特别是早于2.7.1)在创建一个匹配的代理类,如果您使用可选的参数类型提示。

更新学说/共同似乎解决了这个问题。