Skip to content

Regression: appendChild/insertBefore/replaceChild(foreign DOMDocument) — Hierarchy Request not Wrong Document (re-#22698, ext/dom/node.c) #30271

Closed

Description

@PurHur

Category

stdlib · php-src-strict · DOM tree mutation (pillar 4)

Problem

Passing a foreign DOMDocument (another document object) to DOMNode::appendChild(), insertBefore(), or replaceChild() must raise DOMException Wrong Document Error with code 4 (WRONG_DOCUMENT_ERR). The VM raises Hierarchy Request Error (code 3) for appendChild/replaceChild, and insertBefore raises lowercase "Hierarchy request error" with code 0.

Same-document $el->appendChild($el->ownerDocument) correctly stays Hierarchy Request Error code 3 (covered by #22698). This is the foreign-document sibling case.

Repro Zend 8.2.32 VM (2026-08-11)
$el->appendChild($otherDoc) Wrong Document Error / code=4 Hierarchy Request Error / code=3
$el->insertBefore($otherDoc, $ref) Wrong Document Error / code=4 Hierarchy request error / code=0
$el->replaceChild($otherDoc, $old) Wrong Document Error / code=4 Hierarchy Request Error / code=3
$el->appendChild($sameDoc) Hierarchy Request Error / code=3 Hierarchy Request Error / code=3 (OK)

php-src reference

  • php/php-src ext/dom/node.c — dom_node_append_child / dom_node_insert_before / dom_node_replace_child: document mismatch → WRONG_DOCUMENT_ERR before hierarchy type rejection for XML_DOCUMENT_NODE.

PHP implementation target

  • ext/dom/VmDom.php — appendChild / insertBefore / replaceChild: call assertSameDocument before rejecting non-isTreeMutationChild nodes with Hierarchy Request; use DomExceptionConstants::raiseHierarchyRequest() in insertBefore (canonical message + code 3).

Gate snapshot (mandatory pre-work)

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php test/repro/dom_appendchild_doc_cases.php && php bin/vm.php test/repro/dom_appendchild_doc_cases.php'

Done when

  • VM matches Zend on foreign-DOMDocument append/insertBefore/replaceChild (Wrong Document / code 4)
  • Same-document document-as-child still Hierarchy Request / code 3
  • JIT + AOT agree when exercised via shared VmDom path
  • Smallest compliance .phpt guard under test/compliance/cases/dom/
  • php-src-strict; no php-compiler-strict shortcut

Activity

  1. added
    bugSomething isn't working
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Aug 11, 2026
  2. PurHur commented on Aug 11, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler Ext — DOM & XML — starting this run

    Gate snapshot before claim:

  3. PurHur commented on Aug 11, 2026

    @PurHur
    OwnerAuthor

    Status

    VM + JIT fixed and matching Zend. Thin-AOT LiveSlots path still skips NestedJIT exception checks — filed follow-up #30274.

    Verification (2026-08-11)

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php test/repro/dom_mutation_foreign_document_wrong_document.php && php bin/vm.php test/repro/dom_mutation_foreign_document_wrong_document.php && php bin/jit.php test/repro/dom_mutation_foreign_document_wrong_document.php'
    

    Zend/VM/JIT identical:

    appendChild code=4 msg=Wrong Document Error
    insertBefore code=4 msg=Wrong Document Error
    replaceChild code=4 msg=Wrong Document Error
    same code=3 msg=Hierarchy Request Error
    

    Gate snapshot before claim: user_release_ready: yes (gen-0 stale → #28998).

  4. PurHur commented on Aug 11, 2026

    @PurHur
    OwnerAuthor

    Merged via #30277

    Verified: Zend/VM/JIT match on foreign DOMDocument Wrong Document (code 4) and same-document Hierarchy Request (code 3).

    Not covered: thin-AOT LiveSlots — #30274.

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