Re: Re: Extending DOMNode

From: Date: Thu, 15 Feb 2007 16:19:07 +0000
Subject: Re: Re: Extending DOMNode
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-248909@lists.php.net to get a copy of this message
Eli wrote: > Rob Richards wrote: >> 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'); >> ... > > Not good... :-( > > <?php > class MyDOMNode extends DOMNode { > public $x = 100; > } > > $dom = new DOMDocument(); > $dom->registerNodeClass('DOMElement','MyDOMNode'); > ?> > > PHP Fatal error: DOMDocument::registerNodeClass(): Class MyDOMNode is > not derived from DOMElement. > > So I have to extend DOMElement and register MyDOMElement. But all my > nodes should be also based on MyDOMNode. > Problem is that in PHP you can only extend one class in a time, so you > cannot build your own class-tree which extends a base class-tree of DOM. > :-/ maybe the runkit extension can help - no idea how big it might explode in your face if you try to hack the DOM* stuff with runkit :-) you never stated why you want to extend all the DOM classes, maybe there is a different way of achieving what you want (i.e. without going through the hassle of what you seem to have to do at the moment) >

« previous php.general (#248909) next »