简体   繁体   中英

PHP DOMDocument Save() error

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!

Your _construct function is never being executed. If you need a constructor, call it __construct .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM