Skip to content

Regression: DOMNode::replaceChild(foreign node) throws Not found — Zend Wrong Document Error (ext/dom/node.c) #22711

Closed

Description

@PurHur

Category

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

Problem

Replacing a child with a node owned by another document must raise DOMException with message Wrong Document Error and code 4. The VM raises Not found error with code 0.

Distinct from:

Same root shape as insertBefore foreign-node: same-document check is missing or ordered after a not-found path in ext/dom/VmDom.php.

Probed 2026-07-23 on master VM vs host Zend 8.2.32.

Repro Zend 8.2+ VM (2026-07-23)
$e1->replaceChild($nodeFromDoc2, $oldChildInDoc1) Wrong Document Error, code 4 Not found error, code 0

php-src reference

PHP implementation target

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php -r '"'"'
$d1 = new DOMDocument();
$d1->loadXML("<r><a/></r>");
$d2 = new DOMDocument();
$d2->loadXML("<r><b/></r>");
try {
  $d1->documentElement->replaceChild($d2->documentElement->firstChild, $d1->documentElement->firstChild);
  echo "NO_THROW\n";
} catch (DOMException $e) {
  echo "code=", $e->getCode(), " msg=", $e->getMessage(), "\n";
}
'"'"''

Expected: code=4 msg=Wrong Document Error
Actual: code=0 msg=Not found error

Done when

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 Jul 23, 2026
  2. PurHur commented on Jul 24, 2026

    @PurHur
    OwnerAuthor

    Closed via #22913 (same ARG_SEND dual-PropertyFetch collapse as #22710).

    replaceChild($d2->documentElement->firstChild, $d1->documentElement->firstChild) now yields code=4 msg=Wrong Document Error on VM+JIT. Compliance: test/compliance/cases/dom/dom_node_replacechild_wrong_document.phpt.

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