N
N
naneri2014-09-03 09:59:29
PHP
naneri, 2014-09-03 09:59:29

Why is the wrong error thrown when using simple_html_dom?

There is such a code, it goes through the pages and collects information from each and saves it in the database.
For some reason, every time on the second iteration of the loop, the code gives the error
"Call to a member function find() on a non-object in C:\xampp\htdocs\zabor\oc-includes\simple-html\simple_html_dom.php on line 1112 "
Although the problem is in the line $item[$num]->add();
If you comment it out, then there will be no error and the code will normally pass through all iterations.
Tell me where to dig?
Below is the entire code.

while ($num) {
    $url = 'http://some.url.com/category/' . $num;
    $file_headers = @get_headers($url);
    if ($file_headers[0] != 'HTTP/1.1 404 Not Found') {
       $html = new simple_html_dom();
       $html->load_file($url);
       $info[] = (string)$html->find('.pricetitle')[0]->plaintext;
       $data['price'] = intval(str_replace(',', '', $info[0])) * 1000000;
       $item[$num] = new ItemActions();
       $item[$num]->data = $data;
       $item[$num]->add();
     }else{
       break;
    }
  $num++;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-09-03
Protko @Fesor

learning to use xdebug/phpdbg/var_dump.
And which of these lines is 1112? maybe the problem is inside the add method? Without seeing the code at all, you can just sit and guess

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question