Skip to content
Advertisement

Resolve “Fatal Error: Call to a member function children() on null”

I am using PHP HTML DOM Parser to traverse a table DOM on a third party site and print out a particular set of values in a td element.

JavaScript

This works for the first two columns I traverse.

However, in the 3rd column, the $e operation returns Null. The HTML for that element is:

JavaScript

The problem I have, is that it throws a Fatal Error on this element and so the rest of the script won’t run.

The line throwing the error is:

JavaScript

Fatal error: Uncaught Error: Call to a member function children() on null

I need to be able to traverse even if the call is null… What can I do so as not to break the script if one of the column elements is null?

Here is the HTML that I am scraping:

JavaScript

Advertisement

Answer

If I were you I would add few helper methods to avoid similar situation:

JavaScript

This will make sure php will not crash. That being said, you have a lot clean up to do in your code.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement