Skip to content

php-in-php: DOMImplementation — createDocument/createDocumentType without host DOM (ext/dom/php_dom.c) #6140

Description

@PurHur

Category

php-in-php | stdlib

Problem

DOMImplementation is the factory for empty DOM trees (createDocument, createDocumentType, hasFeature). It is required for XML generation without parsing input and is referenced by php-types stubs. This compiler has no DOM surface (#3326 tracks DOMDocument generally); class_exists('DOMImplementation') is false (Jun 2026 audit).

Implementing DOMImplementation first establishes the document factory path that DOMDocument / DOMElement build on.

php-src reference

  • ext/dom/php_dom.c — dom_domimplementation_class_entry, dom_implementation_create_document
  • ext/dom/php_dom.stub.php — DOMImplementation::createDocument, createDocumentType, hasFeature
  • ext/dom/dom_ce.h — class registration

Repro (failure today)

<?php
$impl = new DOMImplementation();
$doctype = $impl->createDocumentType('html', '-//W3C//DTD HTML 4.01//EN', 'http://www.w3.org/TR/html4/strict.dtd');
$doc = $impl->createDocument(null, 'html', $doctype);
$doc->formatOutput = true;
echo $doc->saveXML();
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php
Runtime Output
Zend PHP 8.x (dom) XML string with <!DOCTYPE html> + <html>
bin/vm.php fatal — class DOMImplementation not found

Scope (this repo)

Area Path Notes
Module ext/dom/ (new) PHP class handlers for DOMImplementation, DOMDocumentType, DOMDocument (minimal)
PHP-in-PHP Tree nodes in ext/dom/ + VM object handlers Do not grow runtime/*.c; thin libxml ABI only if unavoidable
libxml host libxml2 for v1 acceptable Pairs with #6058 error buffer migration
Tests test/compliance/cases/dom/implementation_create_document.phpt
JIT/AOT VM-first v1

v1: createDocument, createDocumentType, hasFeature('XML','2.0'). Defer: XPath (#6066), import bridges (#6057).

Done when

  • Repro emits well-formed XML matching Zend shape (DOCTYPE + root element)
  • hasFeature returns expected booleans for XML/HTML features
  • class_exists('DOMImplementation') true; registered as internal class
  • ./script/ci-fast.sh --filter DOMImplementation green
  • PR notes lines not added to lib/AOT/runtime/*.c (PHP path only)

Verification

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

Links

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-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions