Skip to content

Regression: DOMDocument::getElementById() after setIdAttribute on detached node + replaceChild — Zend null, VM finds node (ext/dom/node.c) #23999

Description

@PurHur

Category

bug · php-src-strict · DOM ID map · pillar 4

Problem

Calling setIdAttribute('id', true) on a detached element, then replaceChild() into the document, must not register that id in the document ID map on Zend/libxml (getElementById stays null). VM returns the replacement element. Probed 2026-07-27 vs Zend 8.2.32.

Repro Zend 8.2.32 VM (2026-07-27)
detached setIdAttribute then replaceChild; getElementById('x') null b (replacement)
Control: setIdAttribute on attached node with a new id after replace finds node finds node (OK)
Control: removeChild of id'd node null null (OK)

php-src reference

PHP implementation target

  • ext/dom/ ID-map helpers — only register IDs for nodes that are in the document tree; sync on insert/replace/remove like php-src
  • PHP-in-PHP; no new runtime/ C

Repro

./script/docker-exec.sh -- bash -lc '
php test/repro/maintainer_gap_dom_setidattribute_detached_replace.php
php bin/vm.php test/repro/maintainer_gap_dom_setidattribute_detached_replace.php
'

Done when

  • Detached setIdAttribute + replaceChild → getElementById is null on VM (+ JIT/AOT when in scope)
  • Attached setIdAttribute after insert with a fresh id still resolves
  • Compliance .phpt + keep/update test/repro/maintainer_gap_dom_setidattribute_detached_replace.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