You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A constructor is not called when there are no constructor arguments.
However there are cases where you would want it to be able to be called such as mapping to a doctrine entity that has a collection so the collection is initialised:
class Article
{
#[ORM\ManyToMany(targetEntity: Tag::class, cascade: ['persist'])]
private Collection $tags;
public function __construct()
{
$this->tags = new ArrayCollection();
}
}
It results in this error:
<!-- The property App\Entity\Article::$tags is not readable because it is typed Doctrine\Common\Collections\Collection. You should initialize it or declare a default value instead. (500 Internal Server Error) -->