title: Fatal error: Call to a member function getElementsByTagName()
body: <p>I'm making a CURL request, this code works fine when the ID is present...</p>
  
  <pre><code>$dom = new DOMDocument();
  @$dom-&gt;loadHTML($buffer);
  $obj = $dom-&gt;getElementById('someid')-&gt;getElementsByTagName('tr');
  </code></pre>
  
  <p>But when it is not I get this error</p>
  
  <pre><code>Fatal error: Call to a member function getElementsByTagName()
  </code></pre>
  
  <p>Which is fine and expected, but i'm not sure how to deal with this case properly, what 'if' or 'try catch' should I use to return a 'no data found' message instead?</p>
  
  <p>I have tried for instance this:</p>
  
  <pre><code>$obj = $dom-&gt;getElementById('someid');
  if($obj-&gt;length &gt; 0){
     $rows = $obj-&gt;getElementsByTagName('tr');
  }
  </code></pre>