PHP Fatal error: Call to a member function asXML() on a non

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

PHP Fatal error: Call to a member function asXML() on a non

Post by fugix »

Hey guys,
im trying to do a simplexml_load_file and it is giving me this error...(PHP Fatal error: Call to a member function asXML() on a non-object)..my xml code is pretty basic so im not sure what is going wrong. here is the code

<?php

//$mid = mysql_insert_id();
//$mq = mysql_query("SELECT * FROM updates WHERE userid='".$userid."' AND id='".$mid."'");
//$mrow = mysql_fetch_assoc($mq);
//$mpath = $mrow['musicpath'];

$filename = "/var/www/members/1/playlist.xml";
$xml = simplexml_load_file($filename);

$sxe = new SimpleXMLElement($xml->asXML());

$track = $sxe->addChild("track");
$track->addChild("location", "test");
$track->addChild("title", "test");
echo "<br />";

$sxe->asXML("/var/www/members/1/playlist.xml");

?>
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: PHP Fatal error: Call to a member function asXML() on a

Post by McInfo »

The error message indicates that either $xml or $sxe is not an object, so simplexml_load_file() might have returned something other than an object. The documentation says that the function returns FALSE if an error occurred. The error may be a result of improperly-formatted XML, a non-existent file, or restrictive file permissions.

Enable error_reporting and display_errors directives. Also, see Dealing with XML errors.
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: PHP Fatal error: Call to a member function asXML() on a

Post by fugix »

it was the file permissions. I had to grant www-data write access to the file. Thank you for your reply I appreciate it.
Post Reply