2017-08-17 68 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)在創建一個匹配的代理類,如果您使用可選的參數類型提示。

更新學說/共同似乎解決了這個問題。