Skip to content

Regression: DOMDocument::getElementById() with duplicate setIdAttribute ids — Zend first wins, VM last (ext/dom/document.c) #25275

Description

@PurHur

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

  • Duplicate setIdAttribute → getElementById returns first element on VM (+ JIT/AOT when in scope)
  • Compliance .phpt + keep test/repro/maintainer_gap_dom_getelementbyid_duplicate_setidattribute.php
  • php-src-strict; no php-compiler-strict shortcut

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions