Skip to content

Stdlib: DOMDocument::loadHTML()/saveHTML() missing — HTML parse/serialize fatal (ext/dom/php_dom.c) #14356

Closed

Description

@PurHur

Summary

DOMDocument registers loadXML() / saveXML() but not the HTML counterparts. Calling loadHTML() fatals (undefined method); Zend parses HTML and saveHTML() round-trips.

Blocks typical HTML DOM workflows (scraping, templating) even when XML paths work.

php-src reference

  • ext/dom/php_dom.c — dom_document_load_html(), dom_document_save_html()
  • libxml HTML parser options (LIBXML_HTML_NOIMPLIED, etc.) for parity follow-ups

PHP implementation target

  • ext/dom/VmDom.php — register loadhtml / savehtml on DOMDocument
  • New handlers under ext/dom/ (e.g. DocumentLoadHTML.php, DocumentSaveHTML.php)
  • Reuse existing DomRegistry / element tree where possible; prefer PHP HTML lowering over new runtime/*.c

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_dom_document_load_html.php'
# VM: Fatal undefined method DOMDocument::loadHTML()
# Zend: html + serialized HTML document

test/repro/maintainer_gap_dom_document_load_html.php

Expected (php-src-strict)

  • loadHTML('<p>hi</p>') succeeds; documentElement->nodeName is html
  • saveHTML() returns HTML string (DOCTYPE + body markup like Zend)

Done when

  • loadHTML / saveHTML registered and behave like Zend for the repro
  • Related: loadHTMLFile / saveHTMLFile can be follow-up issues
  • Targeted test; note any runtime/ lines removed if HTML path bypasses C

Activity

  1. added
    enhancementNew feature or request
    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 1, 2026
  2. PurHur commented on Jul 2, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — batch (issue #14356)

  3. PurHur commented on Jul 2, 2026

    @PurHur
    OwnerAuthor

    Merged via #15043. loadHTML('<p>hi</p>') + saveHTML() now match Zend byte-for-byte; compliance dom_document_load_html.phpt green in Docker (VM+JIT).

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 appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions