3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = <<<XML <?xml version="1.0" ?> <root xmlns:foo="uri:foo" /> XML; $doc = new DOMDocument(); $doc->loadXML($xml); // These have special-case handling at the PHP level to redirect the lookup to the libxml namespace store // https://lxr.room11.org/xref/php-src%407.2/ext/dom/element.c#285 var_dump($doc->documentElement->hasAttribute('xmlns:foo')); var_dump($doc->documentElement->getAttribute('xmlns:foo')); // This directly retrieves the libxml attribute store, which does not include the namespace declarations // https://lxr.room11.org/xref/php-src%407.2/ext/dom/node.c#569 var_dump(count($doc->documentElement->attributes)); foreach ($doc->documentElement->attributes as $attribute) { var_dump($attribute->nodeName, $attribute->nodeValue); }

preferences:
16.27 ms | 404 KiB | 5 Q