Page 1 of 1

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

Posted: Sat Mar 19, 2011 1:01 pm
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");

?>

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

Posted: Sat Mar 19, 2011 4:43 pm
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.

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

Posted: Sat Mar 19, 2011 10:27 pm
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.