Search code examples
phpxmlsimplexml

PHP fatal error: Call to a member function asXML() on a non-object


I'm attempting to run a php script to parse Google Calendar XML and I keep getting the following error:

Call to a member function asXML() on a non-object in /index.php on line 120

Here's a link to my code (I've notated Line 120 - IT IS LINE 38 ON PASTEBIN) http://pastebin.com/bMHXfbkD

Anybody with any ideas / fixes would be much appreciated!

UPDATE @Clover and @Phil have suggested I remove the line in question, which I did, and got this:

Notice: Trying to get property of non-object in /Library/WebServer/Documents/index2.php on line 125

Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/index2.php on line 125


Solution

  • simplexml_load_file function can return FALSE, so make a test before using it.

    By the way, in your case, just remove the line, it does nothing :)