title: Fatal error: Uncaught Error: Call to a member function find() on null using Simple HTML DOM
body: <p>I'm using Simple HTML DOM to get elements and values from a website I'm scraping. It works great, but every 23,000 pages or so, I hit the equivalent of a 404 page not found, in which the normal html structure is not present. This results in a fatal error I want to escape without breaking the page.</p>
  
  <p>Here is the full error report:</p>
  
  <p><strong>Fatal error:</strong> Uncaught Error: Call to a member function find() on null in C:\xampp\htdocs\scrape\simple_html_dom.php:1113 Stack trace: #0 C:\xampp\htdocs\scrape\scrape_detailtable.php(133): simple_html_dom->find('div[id=detailta...') #1 {main} thrown in <strong>C:\xampp\htdocs\scrape\simple_html_dom.php</strong> on line <strong>1113</strong></p>
  
  <p>Here are the lines in my script where the error occurs:</p>
  
  <pre><code>$doc = new simple_html_dom($record_content);
  if ( ! is_null($doc-&gt;find("div[id=detailtable]")) ) // &lt;-- this line
  </code></pre>
  
  <p><code>$record_content</code> is the html retrieved using a cURL.</p>
  
  <p>I've tried </p>
  
  <pre><code>if( ! isset($doc-&gt;find("div[id=detailtable]")) ) , 
  if( ! is_null($doc-&gt;find("div[id=detailtable]")) ) , 
  if( ! empty($doc-&gt;find("div[id=detailtable]")) ) , and , 
  if( ! $doc-&gt;find("div[id=detailtable]") )  ...
  </code></pre>
  
  <p>...and the page keeps breaking. I just want to escape processing on condition of the existence of div[id=detailtable].</p>
  
  <p><strong>update on 6/30/2016</strong> </p>
  
  <p>I got another PHP error trying different escape and "detect not null" methods (Maybe this is new with PHP 7). Eventually I tried something where PHP threw this suggestion, along with the error: (paraphrasing) "You can use null !== expression"</p>
  
  <p>So now my code reads: <code>if ( null !== $doc-&gt;find( 'a' ) ){</code></p>
  
  <p>Blah! still getting "Uncaught Error: Call to a member function find() on null" so I guess null !== expression doesn't really work.</p>