Re: Extending DOMNode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Eli wrote:
<?php
class MyDOMNode extends DOMNode {
    public $v = 10;
    function __construct() {}
}

$dom = new DOMDocument();
$dom->registerNodeClass('DOMNode','MyDOMNode');

$dom->loadXML('<root><a/></root>');
echo $dom->firstChild->v;  #<-- not outputs 10
?>

But I get the notice:
PHP Notice:  Undefined property:  DOMElement::$v in ...

I want the extension to be valid for all DOM nodes that are derived from DOMNode, such as DOMElement, DOMAttr, DOMNodeList, DOMText, etc...
I try not to extend all the classes one by one.

Due to the internals of the DOM extension, you need to register the class types that are actually instantiated and not the underlying base DOMNode class. Unfortunately in your case this means you need to register all of those classes separately.

$dom->registerNodeClass('DOMElement','MyDOMNode');
$dom->registerNodeClass('DOMAttr','MyDOMNode');
$dom->registerNodeClass('DOMText','MyDOMNode');
...

Rob

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux