Skip to content

AOT: loadXML DTD ID getElementById finds only first element — later IDs null + detached from tree (ext/dom/document.c) #34696

Description

@PurHur

Category

stdlib · AOT / ext/dom

Problem

User-script AOT DOMDocument::loadXML() with a DTD ATTLIST … ID indexes only the first matching element (DomParseSimpleXmlIdsJitHelper::scanFirstAttributeValue). Later IDs return null from getElementById(). The first hit is also a detached shadow node (=== tree child is false; parentNode empty), not the live documentElement child. Zend/VM return the live tree node for every ID.

Repro Zend 8.2+ / VM AOT (master @ eb638b2)
DTD two <e id="a|b">; getElementById('a') tree child, parentNode=r, text 1 detached text 1, parentNode empty
getElementById('b') tree child text 2 null

Root cause: (1) ID scan is first-only per element name; (2) materializeIndexedElement creates orphan map entries before syncChildrenFromXml; (3) thin-AOT getElementById single-slot cache miss falls through to NestedJIT only, never PROP_ELEMENT_ID_MAP.

php-src reference

PHP implementation target

  • ext/dom/DomParseSimpleXmlIdsJitHelper.php — scan all DTD ID / xml:id elements (first-wins per id value)
  • ext/dom/JitDomDocumentElement.php / JitDomLoadXMLUserScript.php — register live syncChildren nodes into the id map; drop orphan materializeIndexedElement pre-pass
  • ext/dom/JitDomGetElementById.php — on element-cache miss, consult PROP_ELEMENT_ID_MAP before NestedJIT

Repro

./script/docker-exec.sh -- bash -lc 'php bin/compile.php -o /tmp/g.bin test/repro/issue_XXXX_dom_loadxml_multi_dtd_id_aot.php && /tmp/g.bin'

Done when

  • AOT getElementById for every DTD ID matches Zend textContent
  • Returned node === corresponding documentElement child (parentNode is the root)
  • Existing dom_loadxml_getelementbyid_user_script.phpt still green
  • ./script/aot-smoke.sh stays 8/8
  • AOT fixture under test/fixtures/aot/cases/

claim: DOM/XML agent — implementing multi-ID loadXML getElementById + live tree registration.

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:compilerCompiler / CFG / JITbugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions