However I'm getting an annoying error:
Fatal error: KMLElement::__construct() [function.--construct]: Cannot write property in...
This is a problem I can't seem to resolve - there is no way to set or overload the DOMNode->ownerDocument property, which means my KMLDocument cannot tell a new KMLElement its ownerDocument because PHP5 reports the property as read-only - even when inherited (in real OO it'd be unavailable if private, and available if protected or public.
DOMNodes created without an ownerDocument are read-only, which means the new element is next to useless, and there appears to be no way to set this property when the new element is being created by a method in a class extended from DOMDocument.
If the element was created using DOMDocument->createElement() method then ownerDocument is set correctly, but there is no way to get it to create a KMLElement as I need.
Code: Select all
class KMLDocument extends DOMDocument {
public function createElement($name, $value=null) {
if(KMLSchema::isValidTagName($name)) {
$ret = new KMLElement($name, $value, $this); // create the new element with this Document as owner
}
else
throw new DOMException(DOM_NOT_SUPPORTED_ERR);
return $ret;
}
}
// ... more class definition here
}
class KMLElement extends DOMElement {
function __construct($name, $value='', $owner=null, $namespaceURI=null) {
if(!$owner instanceof KMLDocument)
throw new DOMException(DOM_NOT_FOUND_ERR); // illegal owner
parent::__construct($name, $value, $namespaceURI);
$this->ownerDocument = $owner; //** this line causes a Fatal Error
}
// ... more class definition here
}