Skip to content

Stdlib: ext/dom — DOMDocument/DOMElement XML tree API (ext/dom parity) #3326

Description

@PurHur

Category

stdlib

Problem

XML/HTML processing via DOMDocument / DOMElement (ext/dom) is missing (class_exists('DOMDocument') → false). Feeds, config parsers, RSS readers, and PHPUnit-style tools expect the DOM OOP API — not only string helpers like strip_tags().

Verified Jun 2026:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "var_export(class_exists(\"DOMDocument\"));"
php -r "var_export(class_exists(\"DOMDocument\"));"
'
# VM: false · Zend (dom ext): true

php-src reference

Repro (failure today)

<?php
$doc = new DOMDocument();
$doc->loadXML('<root><item id="1">a</item></root>');
$item = $doc->getElementsByTagName('item')->item(0);
echo $item->getAttribute('id'), $item->textContent, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_dom_load_xml.php
php bin/vm.php repro_dom_load_xml.php 2>&1 | head -3
'
Runtime Output
Zend (ext/dom) 1a
bin/vm.php Class "DOMDocument" not found

Scope (this repo)

Layer Path Notes
Module ext/dom/Module.php (new) Register DOMDocument, DOMElement, DOMNode, DOMNodeList, DOMException
VM v1 ext/dom/VmDom.php libxml2 via thin FFI/trampoline (Docker image libxml2) — no large C DOM logic in runtime/
Methods v1 loadXML, saveXML, createElement, getElementsByTagName, item, getAttribute, textContent, appendChild
Phase 2 loadHTML, XPath, DOMDocumentFragment (#6317) separate issues OK
Tests test/compliance/cases/stdlib/dom_document_load_xml.phpt @requires extension dom on Zend leg
Matrix script/capability-matrix.php VM yes; JIT/AOT defer

PHP-in-PHP: DOM tree semantics in ext/dom/ PHP classes; C limited to libxml2 call trampoline if PHP cannot link libxml2 directly.

Done when

  • Repro prints 1a on VM in Docker (php-compiler:22.04-dev with libxml2)
  • Malformed XML: policy matches Zend (fatal or DOMException — document choice in PHPT)
  • class_exists('DOMDocument') true; instanceof DOMNode works for elements
  • ./script/ci-fast.sh --filter dom_document_load_xml green
  • Capability matrix documents dom classes (VM yes)

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter dom_document_load_xml'

Related

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 machineenhancementNew feature or requestimplementation-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