Skip to content

Require PHP 8.4 and use the new DOM API - #36

Merged
janedbal merged 4 commits into
masterfrom
new-dom-api
Aug 26, 2026
Merged

Require PHP 8.4 and use the new DOM API#36
janedbal merged 4 commits into
masterfrom
new-dom-api

Conversation

@janedbal

Copy link
Copy Markdown
Member

Summary

  • Bump the minimum PHP version to 8.4.
  • Replace DOMDocument::loadXML / loadHTML with Dom\XMLDocument::createFromString and Dom\HTMLDocument::createFromString.
  • Keep the API surface: XmlLoader::loadXml(), XmlLoader::loadHtml(), and XmlException wrapping LibXMLError stay the same.
  • Keep the safety guarantees: LIBXML_NONET | LIBXML_NOBLANKS for XML, empty-input rejection, and DOCTYPE rejection.
  • Run CI on PHP 8.4 and 8.5 only.

Breaking changes (v4)

  • loadXml() returns Dom\XMLDocument and loadHtml() returns Dom\HTMLDocument. These classes do not extend DOMDocument.
  • The new DOM classes follow the DOM spec. For example, nodeValue on an element returns null; use textContent instead.
  • loadHtml() parses with the HTML5 parser (Lexbor). The HTML5 parser recovers from malformed markup, so loadHtml() throws only on empty input or a hard parser failure. The old HTML 4 parser had almost the same failure behavior.

Notes

  • The new API does not force LIBXML_NONET by itself. The loader still passes it explicitly.
  • Parse-error detail still comes from libxml_get_last_error(), so XmlException::getError() keeps line and column information.
  • Tests assert the entity-expansion errors with wildcard patterns, because libxml changed those messages in 2.11.

The loader now uses Dom\XMLDocument and Dom\HTMLDocument.
The method names and the exception contract do not change.
The return types change, so this is a v4 major release.
XmlException::getPrevious() now returns the original DOMException.
The HTML5 parser recovers from malformed markup.
loadHtml throws only for empty input, same as v3 in practice.
@janedbal
janedbal merged commit c6e4be5 into master Aug 26, 2026
2 checks passed
@janedbal
janedbal deleted the new-dom-api branch August 26, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant