Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine php7+ type hinting, Declaration of Proxies error

I am constantly getting this weird error

  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

Why on earth is this happening? Why can I not have

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

    return $this;
}

as my setter? It works if I remove '?', but I do need it for other purpose

like image 874
hvertous Avatar asked Aug 17 '17 13:08

hvertous


1 Answers

As I mentioned in the comments already: According to this issue older versions of doctrine/common (specifically older than 2.7.1) might have problems creating a matching proxy class if you are using optional parameter type hints.

Updating doctrine/common seems to fix the problem.

like image 112
Tobias Xy Avatar answered Oct 29 '22 00:10

Tobias Xy