Category
bug · php-src-strict · DOM ID map · pillar 4
Problem
When two elements share the same id attribute and both call setIdAttribute('id', true), Zend getElementById() returns the first element in document order; VM returns the last. Probed 2026-07-30 vs Zend 8.2.32.
| Repro |
Zend 8.2.32 |
VM (2026-07-30) |
<a id="x"/><b id="x"/> both setIdAttribute; getElementById('x')->nodeName |
a |
b |
php-src reference
PHP implementation target
ext/dom/ ID-map — do not overwrite an existing id entry on a second setIdAttribute (match Zend first-wins); PHP-in-PHP
Repro
./script/docker-exec.sh -- bash -lc '
php test/repro/maintainer_gap_dom_getelementbyid_duplicate_setidattribute.php
php bin/vm.php test/repro/maintainer_gap_dom_getelementbyid_duplicate_setidattribute.php
'
Inline:
$d = new DOMDocument();
$d->loadXML('<r><a id="x"/><b id="x"/></r>');
$a = $d->documentElement->firstChild;
$b = $a->nextSibling;
$a->setIdAttribute('id', true);
$b->setIdAttribute('id', true);
echo $d->getElementById('x')->nodeName, "\n";
// Zend: a VM: b
Done when
Category
bug· php-src-strict · DOM ID map · pillar 4Problem
When two elements share the same
idattribute and both callsetIdAttribute('id', true), ZendgetElementById()returns the first element in document order; VM returns the last. Probed 2026-07-30 vs Zend 8.2.32.<a id="x"/><b id="x"/>bothsetIdAttribute;getElementById('x')->nodeNameabphp-src reference
ext/dom/document.c—getElementById/ ID hashtable (first registration wins)ext/dom/element.c—setIdAttributePHP implementation target
ext/dom/ID-map — do not overwrite an existing id entry on a secondsetIdAttribute(match Zend first-wins); PHP-in-PHPRepro
Inline:
Done when
setIdAttribute→getElementByIdreturns first element on VM (+ JIT/AOT when in scope).phpt+ keeptest/repro/maintainer_gap_dom_getelementbyid_duplicate_setidattribute.php