You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Dom\XMLDocument::C14N() seems broken compared to DOMDocument::C14N() #20444
Shouldn't the new \Dom\XMLDocument class give the same result as the "old" \DOMDocument class?
PHP Version
PHP 8.4.14 (cli) (built: Oct 24 2025 19:07:34) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.14, Copyright (c) Zend Technologies
with Zend OPcache v8.4.14, Copyright (c), by Zend Technologies
Operating System
Alpine Linux v3.22.2 (php:8.4-fpm-alpine docker image)
changed the title [-]`Dom\XMLDocument::C14N()` seems broken[/-][+]`Dom\XMLDocument::C14N()` seems broken compared to `DOMDocument::C14N()`[/+]on Nov 10, 2025
Yes I figured that out too when I experimented with the code yesterday evening.
The root cause is that the new DOM code stores namespaces in a different way, and C14N has very strict rules about how namespaces should get stored. So I need to manually insert fake temporary declarations to satisfy the constraints of the C14N engine.
I tried other tricks but the problem is that in the modern DOM specification there are no real namespace declarations nodes (they're proper attributes), so we don't have a fixed insertion point.
Activity
[-]`Dom\XMLDocument::C14N()` seems broken[/-][+]`Dom\XMLDocument::C14N()` seems broken compared to `DOMDocument::C14N()`[/+]ndossche commentedon Nov 11, 2025
Didn't yet find something better than this https://gist.github.com/ndossche/34a44c33f54d253ebe961203ef59a2e6
aprat84 commentedon Nov 11, 2025
The non-exclusive variant also produces weird results, repeating the namespace declaration in every first level node:
The first one outputs this:
While the second one outputs this:
Also note that the
DOMDocument::C14N()method produces the same results as thexmllint [--c14n|--exc-c14n] <file>command (libxml2-2.13.9-r0).ndossche commentedon Nov 11, 2025
Yes I figured that out too when I experimented with the code yesterday evening.
The root cause is that the new DOM code stores namespaces in a different way, and C14N has very strict rules about how namespaces should get stored. So I need to manually insert fake temporary declarations to satisfy the constraints of the C14N engine.
I tried other tricks but the problem is that in the modern DOM specification there are no real namespace declarations nodes (they're proper attributes), so we don't have a fixed insertion point.
Fix phpGH-20444: Dom\XMLDocument::C14N() seems broken compared to DOM…
Fix GH-20444: Dom\XMLDocument::C14N() seems broken compared to DOMDoc…
Merge branch 'PHP-8.4' into PHP-8.5
Merge branch 'PHP-8.5'