title: Symfony 4 - Object of class could not be converted to String
body: <p>After looking over the internet and here I didn' find something useful for me.
  I'm currently creating a CRUD. Every 'Entreprise' having one or multiple 'Site' and I'm currently doing the CRUD for Site. I've made it by doing the <code>make:form</code> command.
  Whhen I'm going to create a site the following error appear :</p>
  
  <blockquote>
    <p>Catchable Fatal Error: Object of class App\Entity\Entreprise could not
    be converted to string</p>
  </blockquote>
  
  <p>I've tried to add the function <code>__toString()</code>  as i saw. But maybe i didn't add it crrectly it changes nothing so I removed it.</p>
  
  <p>My controller to create a site looks like this : </p>
  
  <pre class="lang-php prettyprint-override"><code>        /**
           * @Route("admin/sites/new", name="admin.sites.new")
           * @param Request $request
           * @return RedirectResponse|Response
           */
          public function new (Request $request)
          {
              $site = new Site();
              $form = $this-&gt;createForm(SiteType::class, $site);
              $form-&gt;handleRequest($request);
  
              if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()){
                  $this-&gt;em-&gt;persist($site);
                  $this-&gt;em-&gt;flush();
                  $this-&gt;addFlash('success', 'Site crée avec succès');
                  return $this-&gt;redirectToRoute('admin.sites.index');
              }
              return $this-&gt;render('admin/sites/create.html.twig', [
                  'site' =&gt; $site,
                  'form' =&gt; $form-&gt;createView()
              ]);
          }
      }
  </code></pre>
  
  <p>My SiteType generate by the <code>make:form</code> commande :</p>
  
  <pre class="lang-php prettyprint-override"><code>        /**
           * @Route("admin/sites/new", name="admin.sites.new")
           * @param Request $request
           * @return RedirectResponse|Response
           */
          public function new (Request $request)
          {
              $site = new Site();
              $form = $this-&gt;createForm(SiteType::class, $site);
              $form-&gt;handleRequest($request);
  
              if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()){
                  $this-&gt;em-&gt;persist($site);
                  $this-&gt;em-&gt;flush();
                  $this-&gt;addFlash('success', 'Site crée avec succès');
                  return $this-&gt;redirectToRoute('admin.sites.index');
              }
              return $this-&gt;render('admin/sites/create.html.twig', [
                  'site' =&gt; $site,
                  'form' =&gt; $form-&gt;createView()
              ]);
          }
      }
  </code></pre>
  
  <p>So here are my ENTITY</p>
  
  <p><strong>Entreprise</strong></p>
  
  <pre><code>namespace App\Entity;
  
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity(repositoryClass="App\Repository\EntrepriseRepository")
   */
  class Entreprise
  {
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\Column(type="string", length=255)
       */
      private $entreprise_nom;
  
      /**
       * @ORM\Column(type="string", length=255)
       */
      private $entreprise_siret;
  
      /**
       * @ORM\Column(type="string", length=10)
       */
      private $entreprise_telephone;
  
      /**
       * @ORM\Column(type="string", length=255)
       */
      private $entreprise_salesforce_number;
  
      /**
       * @ORM\Column(type="string", length=255)
       */
      private $entreprise_compte_client;
  
      /**
       * @ORM\Column(type="string", length=255)
       */
      private $entreprise_raison_sociale;
  
      /**
       * @ORM\Column(type="string", length=255)
       */
      private $entreprise_APE;
  
      /**
       * @ORM\Column(type="text", nullable=true)
       */
      private $entreprise_image_link;
  
      /**
       * @ORM\OneToMany(targetEntity="App\Entity\Site", mappedBy="entreprise_id")
       */
      private $entreprise_id;
  
      /**
       * @ORM\OneToMany(targetEntity="App\Entity\Catalogue", mappedBy="entreprise_id")
       */
      private $entreprise_catalogue_id;
  
      public function __construct()
      {
          $this-&gt;entreprise_id = new ArrayCollection();
          $this-&gt;entreprise_catalogue_id = new ArrayCollection();
      }
  
      public function getId(): ?int
      {
          return $this-&gt;id;
      }
  
      public function getEntrepriseNom(): ?string
      {
          return $this-&gt;entreprise_nom;
      }
  
      public function setEntrepriseNom(string $entreprise_nom): self
      {
          $this-&gt;entreprise_nom = $entreprise_nom;
  
          return $this;
      }
  
      public function getEntrepriseSiret(): ?string
      {
          return $this-&gt;entreprise_siret;
      }
  
      public function setEntrepriseSiret(string $entreprise_siret): self
      {
          $this-&gt;entreprise_siret = $entreprise_siret;
  
          return $this;
      }
  
      public function getEntrepriseTelephone(): ?int
      {
          return $this-&gt;entreprise_telephone;
      }
  
      public function setEntrepriseTelephone(int $entreprise_telephone): self
      {
          $this-&gt;entreprise_telephone = $entreprise_telephone;
  
          return $this;
      }
  
      public function getEntrepriseSalesforceNumber(): ?string
      {
          return $this-&gt;entreprise_salesforce_number;
      }
  
      public function setEntrepriseSalesforceNumber(string $entreprise_salesforce_number): self
      {
          $this-&gt;entreprise_salesforce_number = $entreprise_salesforce_number;
  
          return $this;
      }
  
      public function getEntrepriseCompteClient(): ?string
      {
          return $this-&gt;entreprise_compte_client;
      }
  
      public function setEntrepriseCompteClient(string $entreprise_compte_client): self
      {
          $this-&gt;entreprise_compte_client = $entreprise_compte_client;
  
          return $this;
      }
  
      public function getEntrepriseRaisonSociale(): ?string
      {
          return $this-&gt;entreprise_raison_sociale;
      }
  
      public function setEntrepriseRaisonSociale(string $entreprise_raison_sociale): self
      {
          $this-&gt;entreprise_raison_sociale = $entreprise_raison_sociale;
  
          return $this;
      }
  
      public function getEntrepriseAPE(): ?string
      {
          return $this-&gt;entreprise_APE;
      }
  
      public function setEntrepriseAPE(string $entreprise_APE): self
      {
          $this-&gt;entreprise_APE = $entreprise_APE;
  
          return $this;
      }
  
      public function getEntrepriseImageLink(): ?string
      {
          return $this-&gt;entreprise_image_link;
      }
  
      public function setEntrepriseImageLink(?string $entreprise_image_link): self
      {
          $this-&gt;entreprise_image_link = $entreprise_image_link;
  
          return $this;
      }
  
      /**
       * @return Collection|Site[]
       */
      public function getEntrepriseId(): Collection
      {
          return $this-&gt;entreprise_id;
      }
  
      public function addEntrepriseId(Site $entrepriseId): self
      {
          if (!$this-&gt;entreprise_id-&gt;contains($entrepriseId)) {
              $this-&gt;entreprise_id[] = $entrepriseId;
              $entrepriseId-&gt;setEntrepriseId($this);
          }
  
          return $this;
      }
  
      public function removeEntrepriseId(Site $entrepriseId): self
      {
          if ($this-&gt;entreprise_id-&gt;contains($entrepriseId)) {
              $this-&gt;entreprise_id-&gt;removeElement($entrepriseId);
              // set the owning side to null (unless already changed)
              if ($entrepriseId-&gt;getEntrepriseId() === $this) {
                  $entrepriseId-&gt;setEntrepriseId(null);
              }
          }
  
          return $this;
      }
  
  
  }
  </code></pre>
  
  <p>And here is </p>
  
  <p><strong>Site</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>
  namespace App\Entity;
  
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\Common\Collections\Collection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
  * @ORM\Entity(repositoryClass="App\Repository\SiteRepository")
  */
  class Site
  {
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;
  
    /**
     * @ORM\Column(type="string", length=255)
     */
    private $site_nom;
  
    /**
     * @ORM\Column(type="string", length=255)
     */
    private $site_raison_sociale;
  
    /**
     * @ORM\Column(type="string", length=255)
     */
    private $site_APE;
  
    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Client", mappedBy="site_id")
     */
    private $site_id;
  
    /**
     * @ORM\OneToOne(targetEntity="App\Entity\Adresse", cascade={"persist", "remove"})
     * @ORM\JoinColumn(nullable=false)
     */
    private $adresse_id;
  
    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Entreprise", inversedBy="entreprise_id")
     * @ORM\JoinColumn(nullable=false)
     */
    private $entreprise_id;
  
    public function __construct()
    {
        $this-&gt;site_id = new ArrayCollection();
    }
  
    public function getId(): ?int
    {
        return $this-&gt;id;
    }
  
    public function getSiteNom(): ?string
    {
        return $this-&gt;site_nom;
    }
  
    public function setSiteNom(string $site_nom): self
    {
        $this-&gt;site_nom = $site_nom;
  
        return $this;
    }
  
    public function getSiteRaisonSociale(): ?string
    {
        return $this-&gt;site_raison_sociale;
    }
  
    public function setSiteRaisonSociale(string $site_raison_sociale): self
    {
        $this-&gt;site_raison_sociale = $site_raison_sociale;
  
        return $this;
    }
  
    public function getSiteAPE(): ?string
    {
        return $this-&gt;site_APE;
    }
  
    public function setSiteAPE(string $site_APE): self
    {
        $this-&gt;site_APE = $site_APE;
  
        return $this;
    }
  
    /**
     * @return Collection|Client[]
     */
    public function getSiteId(): Collection
    {
        return $this-&gt;site_id;
    }
  
    public function addSiteId(Client $siteId): self
    {
        if (!$this-&gt;site_id-&gt;contains($siteId)) {
            $this-&gt;site_id[] = $siteId;
            $siteId-&gt;addSiteId($this);
        }
  
        return $this;
    }
  
    public function removeSiteId(Client $siteId): self
    {
        if ($this-&gt;site_id-&gt;contains($siteId)) {
            $this-&gt;site_id-&gt;removeElement($siteId);
            $siteId-&gt;removeSiteId($this);
        }
  
        return $this;
    }
  
    public function getAdresseId(): ?Adresse
    {
        return $this-&gt;adresse_id;
    }
  
    public function setAdresseId(Adresse $adresse_id): self
    {
        $this-&gt;adresse_id = $adresse_id;
  
        return $this;
    }
  
    public function getEntrepriseId(): ?Entreprise
    {
        return $this-&gt;entreprise_id;
    }
  
    public function setEntrepriseId(?Entreprise $entreprise_id): self
    {
        $this-&gt;entreprise_id = $entreprise_id;
  
        return $this;
    }
  
    public function __toString()
    {
        return $this-&gt;getSiteNom();
    }
  }
  
  </code></pre>
  
  <p>I didn't know what's wrong. Maybe the <code>__toString</code> I didn't write correclty !
  I've wrote :</p>
  
  <pre class="lang-php prettyprint-override"><code>public function __toString()
      {
          return $this-&gt;getSiteNom();
      }
  }
  </code></pre>