3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Dom\XMLDocument::C14N() drops namespace declarations on DOM-built documents * * When a Dom\XMLDocument is built via the DOM API (createElementNS, appendChild), * non-exclusive C14N() strips all namespace declarations while keeping prefixed * element names, producing invalid XML that cannot be re-parsed. * * This does NOT happen when: * - The document is parsed from a string (createFromString) * - Using legacy DOMDocument (DOM-built or parsed) * - Using exclusive C14N (C14N(exclusive: true)) * * Related: https://github.com/php/php-src/issues/20444 * Possibly related fix: https://github.com/php/php-src/commit/40c291cf932c31a302fa584bb50b6edb199fb07e * (but still broken on PHP 8.4.19) */ echo "PHP " . PHP_VERSION . PHP_EOL . PHP_EOL; // 1. DOM-built document: C14N drops namespace declarations $doc = Dom\XMLDocument::createEmpty(); $root = $doc->createElementNS("urn:envelope", "env:Root"); $doc->appendChild($root); $child = $doc->createElementNS("urn:child", "x:Child"); $root->appendChild($child); echo "DOM-built Dom\XMLDocument" . PHP_EOL; echo " saveXML: " . trim($doc->saveXML()) . PHP_EOL; echo " C14N: " . $doc->C14N() . PHP_EOL; // Expected: <env:Root xmlns:env="urn:envelope"><x:Child xmlns:x="urn:child"></x:Child></env:Root> // Actual: <env:Root><x:Child></x:Child></env:Root> // ^ namespace declarations are missing, this is not valid XML echo PHP_EOL; // 2. Same structure parsed from string: C14N works correctly $doc2 = Dom\XMLDocument::createFromString( '<env:Root xmlns:env="urn:envelope"><x:Child xmlns:x="urn:child"/></env:Root>' ); echo "Parsed Dom\XMLDocument" . PHP_EOL; echo " C14N: " . $doc2->C14N() . PHP_EOL; // Correct: <env:Root xmlns:env="urn:envelope"><x:Child xmlns:x="urn:child"></x:Child></env:Root> echo PHP_EOL; // 3. Legacy DOMDocument DOM-built: C14N works correctly $doc3 = new DOMDocument(); $root3 = $doc3->createElementNS("urn:envelope", "env:Root"); $doc3->appendChild($root3); $child3 = $doc3->createElementNS("urn:child", "x:Child"); $root3->appendChild($child3); echo "DOM-built DOMDocument (legacy)" . PHP_EOL; echo " C14N: " . $doc3->C14N() . PHP_EOL; // Correct: <env:Root xmlns:env="urn:envelope"><x:Child xmlns:x="urn:child"></x:Child></env:Root> echo PHP_EOL; // 4. Exclusive C14N on DOM-built document: works correctly echo "DOM-built Dom\XMLDocument (exclusive C14N)" . PHP_EOL; echo " C14N: " . $doc->C14N(exclusive: true) . PHP_EOL; // Correct: <env:Root xmlns:env="urn:envelope"><x:Child xmlns:x="urn:child"></x:Child></env:Root>

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.30.0190.00917.35
8.5.20.0370.01117.02
8.5.10.0320.00817.08
8.5.00.0310.00916.46
8.4.180.0280.00919.77
8.4.170.0330.00819.87
8.4.160.0270.00819.87
8.4.150.0290.00719.83
8.4.140.0370.00718.01
8.4.130.0330.01017.99
8.4.120.0310.01217.95
8.4.110.0340.00518.25
8.4.100.0300.01218.05
8.4.90.0360.00817.95
8.4.80.0320.00518.25
8.4.70.0150.00518.25
8.4.60.0220.00718.09
8.4.50.0310.01418.13
8.4.40.0400.00917.82
8.4.30.0430.00617.79
8.4.20.0200.00317.99
8.4.10.0230.00617.79
8.3.300.0170.00418.12
8.3.290.0360.01218.29
8.3.280.0260.00718.36
8.3.270.0270.01116.58
8.3.260.0340.01016.79
8.3.250.0360.00716.63
8.3.240.0400.00616.42
8.3.230.0400.00816.52
8.3.220.0320.00916.54
8.3.210.0260.00516.56
8.3.200.0310.00416.68
8.3.190.0180.00316.64
8.3.180.0150.00416.72
8.3.170.0160.00416.66
8.3.160.0240.00616.66
8.3.150.0280.00616.50
8.3.140.0200.00316.73
8.3.130.0160.00516.66
8.3.120.0140.00416.85
8.3.110.0190.00716.56
8.3.100.0220.00216.45
8.3.90.0360.00816.66
8.3.80.0160.00516.45
8.3.70.0180.00316.66
8.3.60.0170.00516.62
8.3.50.0180.00416.83
8.3.40.0110.00818.02
8.3.30.0130.00218.01
8.3.20.0140.00218.04
8.3.10.0270.00917.97
8.3.00.0270.00817.76

preferences:
51.59 ms | 732 KiB | 5 Q