Reputation: 13
I haven't been able to find the answer to this one. I'm new to php to bear with me.
I've been trying to use the DOMDocument object within a class but when I try and invoke the save() method of the DOMDocument object I get the following error:
Fatal error: Call to a member function save() on a non-object:
Code snippet as follows:
$kmlDoc = new KMLDoc();
$kmlDoc->saveKML();
class KMLDoc
{
public $dom;
public $docNode;
function _construct()
{
$this->dom = new DOMDocument('1.0', 'UTF-8');
$this->dom->formatOutput = true;
// Creates the root KML element and appends it to the root document.
$node = $this->dom->createElementNS('http://earth.google.com/kml/2.1', 'kml');
$parNode = $this->dom->appendChild($node);
// Creates a KML Document element and append it to the KML element.
$dnode = $this->dom->createElement('Document');
$this->docNode = $parNode->appendChild($dnode);
}
function saveKML()
{
$this->dom->save('outputs/test.kml');
}
}
?>
I'm guessing it's something to do with the following: $this->dom->save('outputs/test.kml'); but I can't seem to figure it out.
Many thanks for your help!
Upvotes: 1
Views: 589
Reputation: 146330
Your _construct
function is never being executed. If you need a constructor, call it __construct
.
Upvotes: 1