title: How do I check if object was found in a Doctrine2 repository?
body: <p>I am finding a entity by its PK as follow:</p>
  
  <pre><code>$ent = $em-&gt;getRepository('AppBundle:Representative')-&gt;find($id)
  </code></pre>
  
  <p>What is the right way to check whether <code>$ent</code> is a real Representative object or not? What I mean with <em>real</em> is that <code>$ent</code> currently exists on DB and was returned since I am planning to use the same results for <code>INSERT</code> and <code>UPDATE</code>. In pseudo-code what is on my head is:</p>
  
  <pre><code>if (ent is Representative)
  {
      // Update its values
  } else {
      // Create a new Representative
  }
  </code></pre>
  
  <p>I was thinking in use <code>is_object()</code> or even <code>instanceof</code> but I am not sure if they will do the job or if <code>$ent</code> will be an object even if Representative doesn't exist on DB. Any advice on this? How I can achieve that?</p>