title: How to verify if object variable is set
body: <p>I have a <code>User</code> class which is created when a user logs in</p>
  
  <pre><code>$user = new User($userId);
  </code></pre>
  
  <p>Now to check if a user is logged in, I tried doing</p>
  
  <pre><code>if (isset($user)) {   // user is logged in
  
  } else {   // user is not logged in
  
  }
  </code></pre>
  
  <p>However, <code>isset()</code> doesn't appear to work for objects?  And I've also tried <code>is_object()</code>. Please advise! Hopefully there is a way to do this elegantly, perhaps</p>
  
  <pre><code>if ($user-&gt;isLoggedIn()) {
  
  }
  </code></pre>
  
  <p>Thanks for your time!</p>