2

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!

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Damn, you just beat me to it... :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.