xref: /php-src/ext/dom/tests/gh12870.inc (revision e658f805)
1<?php
2
3function test(?string $uri, string $qualifiedName) {
4    $uri_readable = is_null($uri) ? 'NULL' : "\"$uri\"";
5    echo "--- Testing $uri_readable, \"$qualifiedName\" ---\n";
6    $d = new DOMDocument();
7    $d->appendChild($d->createElement('root'));
8    try {
9        $attr = $d->createAttributeNS($uri, $qualifiedName);
10        $d->documentElement->setAttributeNodeNS($attr);
11        echo "Attr prefix: ";
12        var_dump($attr->prefix);
13        echo "Attr namespaceURI: ";
14        var_dump($attr->namespaceURI);
15        echo "Attr value: ";
16        var_dump($attr->value);
17        echo "root namespaceURI: ";
18        var_dump($d->documentElement->namespaceURI);
19        echo "Equality check: ";
20        $parts = explode(':', $qualifiedName);
21        var_dump($attr === $d->documentElement->getAttributeNodeNS($uri, $parts[count($parts) - 1]));
22        echo $d->saveXML(), "\n";
23    } catch (DOMException $e) {
24        echo "Exception: ", $e->getMessage(), "\n\n";
25    }
26}
27