|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-06-15 08:23 UTC] cmb@php.net
-Status: Open
+Status: Verified
[2020-06-15 08:23 UTC] cmb@php.net
[2024-05-21 08:46 UTC] dennis6101990leon at outlook dot com
[2024-06-01 10:54 UTC] git@php.net
[2024-06-01 10:54 UTC] git@php.net
-Status: Verified
+Status: Closed
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 07:00:01 2025 UTC |
Description: ------------ A DOM id element is supposed to be unique, but sometimes the world is messy. The DOM specification says: > The getElementById(elementId) method, when invoked, must return the first element, > in tree order, within this’s descendants, whose ID is elementId, and null if there > is no such element otherwise. PHP uses libxmls ID Map functionality, which does not allow duplicates. The return value of "xmlAddID" is not checked for the error, so elements with duplicate ID don't cause a problem. However if you remove the first element with an ID, or re-order the elements, then the specifications assumption of returning the first element in tree order does not work anymore. Test script: --------------- <?php $dom = new DOMDocument(); $root = $dom->createElement('html'); $dom->appendChild($root); $el1 = $dom->createElement('p1'); $el1->setAttribute('id', 'foo'); $el1->setIdAttribute('id', true); $root->appendChild($el1); $el2 = $dom->createElement('p2'); $el2->setAttribute('id', 'foo'); $el2->setIdAttribute('id', true); $root->appendChild($el2); unset($el1, $el2); $root->removeChild($dom->getElementById('foo')); var_dump($dom->getElementById('foo')); Expected result: ---------------- Returns Element <p2 id="foo" /> Actual result: -------------- NULL