xref: /PHP-8.0/ext/simplexml/tests/bug41861.phpt (revision f8d79582)
1--TEST--
2Bug #41861 (getNamespaces() returns the namespaces of a node's siblings)
3--SKIPIF--
4<?php if (!extension_loaded("simplexml")) print "skip"; ?>
5--FILE--
6<?php
7
8$xml = simplexml_load_string('<root>
9    <first_node_no_ns />
10    <ns1:node1 xmlns:ns1="#ns1" />
11    <ns2:node2 xmlns:ns2="#ns2" />
12    <ns3:node3 xmlns:ns3="#ns3" />
13    <last_node_no_ns />
14</root>');
15
16$name = $xml->getName();
17$namespaces = $xml->getNamespaces(True);
18echo "root(recursive): '$name' -- namespaces: ", implode(', ', $namespaces), "\n";
19$namespaces = $xml->getNamespaces(False);
20echo "root(non-recursive): '$name' -- namespaces: ", implode(', ', $namespaces), "\n";
21
22foreach (array(null, '#ns1', '#ns2', '#ns3') as $ns)
23{
24    foreach ($xml->children($ns) as $child)
25    {
26        $name = $child->getName();
27        $namespaces = $child->getNamespaces(false);
28
29        echo "children($ns): '$name' -- namespaces: ", implode(', ', $namespaces), "\n";
30    }
31}
32?>
33--EXPECT--
34root(recursive): 'root' -- namespaces: #ns1, #ns2, #ns3
35root(non-recursive): 'root' -- namespaces:
36children(): 'first_node_no_ns' -- namespaces:
37children(): 'last_node_no_ns' -- namespaces:
38children(#ns1): 'node1' -- namespaces: #ns1
39children(#ns2): 'node2' -- namespaces: #ns2
40children(#ns3): 'node3' -- namespaces: #ns3
41