note 78337 deleted from domdocument.registernodeclass by bjori
| From: | bjori@php.net | Date: | Tue, 28 Oct 2008 09:24:47 +0000 |
| Subject: | note 78337 deleted from domdocument.registernodeclass by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145855@lists.php.net to get a copy of this message | ||
Note Submitter: nobody at dontlikespam dot com
----
There's a bug (similar reported 3 years ago as #28473 but tagged as "bogus" by lazy
developer) in this function. When you eg. create own DOMElement class that have some properties and
then try to set those properties on several nodes, only value set on the last node will be
available.
<?php
class test extends DOMElement {
public $prop;
}
$doc = new DOMDocument();
$doc->registerNodeClass('DOMElement','test');
$doc->loadXML('<root><t1></t1><t2></t2></root>');
$tn = $doc->childNodes->item(0)->childNodes->item(0);
$tn->prop = 'test1'; // Set on T1 tag
$tn = $doc->childNodes->item(0)->childNodes->item(1);
$tn->prop = 'test2'; // Set on T2 tag
echo $doc->childNodes->item(0)->childNodes->item(0)->prop."<br>";
echo $doc->childNodes->item(0)->childNodes->item(1)->prop."<br>";
?>
Result: <br>test2<br>
Should be: test1<br>test2<br>
That and fact that one can't get unique PHP object identifcator (not XML attribute) of every
node (also DOMText or DOMAttr) makes this PHP's DOMXML just a simple XML traverse function and
not (as should be) powerful way to do custom (and FAST - there is no problem in rewriting DOM tree
to own objects but where's in that the sense of using DOM anyway?) work with XML documents.
DOM implementation in PHP sucks and it would be better to not provide one (and make users create
their own) than include that crap (and make users to think that they are able to do something in
notime while it takes week).