From:             hubert dot roksor at gmail dot com
Operating system: 
PHP version:      5CVS-2007-06-30 (CVS)
PHP Bug Type:     SimpleXML related
Bug description:  getNamespaces() returns the namespaces of a node's siblings

Description:
------------
In addition to a node's own namespaces, getNamespaces() seems to return
the namespaces of its latter siblings.

In the reproduce code below, we create a tree composed of 5 nodes: the
first and last nodes have no namespaces and the 3 nodes in-between each
have their own namespace. We observe that getNamespaces() returns all 3
namespaces for the first node, altough it should have none, then 3, 2, 1
namespaces for the subsequent nodes (which should only have one each) then
finally no namespace for the last node, as expected.

children(), on the other hand, behaves correctly and does not find the
nodes under those "extra" namespaces so I guess the problem is located in
getNamespaces().

Thanks for reading :]


Tested on:

PHP 5.2.4-dev (cli) (built: Jun 30 2007 12:04:20)
WinXP
libxml2 2.6.26
SimpleXML Revision: 1.151.2.22.2.29

PHP 5.2.2-pl1-gentoo (cli) (built: May 24 2007 00:26:35)
libxml 2.6.27
SimpleXML Revision: 1.151.2.22.2.26

Reproduce code:
---------------
$xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8" ?>
<root>
        <first_node_no_ns />
        <ns1:node1 xmlns:ns1="#ns1" />
        <ns2:node2 xmlns:ns2="#ns2" />
        <ns3:node3 xmlns:ns3="#ns3" />
        <last_node_no_ns />
</root>');

foreach (array(null, '#ns1', '#ns2', '#ns3') as $ns)
{
        foreach ($xml->children($ns) as $child)
        {
                $name = $child->getName();
                $namespaces = $child->getNamespaces(false);

                echo "children($ns) has found '$name' -- Its namespaces: ", 
implode(',
', $namespaces), "\n";
        }
}

Expected result:
----------------
children() has found 'first_node_no_ns' -- Its namespaces: #ns1, #ns2,
#ns3
children() has found 'last_node_no_ns' -- Its namespaces:
children(#ns1) has found 'node1' -- Its namespaces: #ns1, #ns2, #ns3
children(#ns2) has found 'node2' -- Its namespaces: #ns2, #ns3
children(#ns3) has found 'node3' -- Its namespaces: #ns3

Actual result:
--------------
children() has found 'first_node_no_ns' -- Its namespaces:
children() has found 'last_node_no_ns' -- Its namespaces:
children(#ns1) has found 'node1' -- Its namespaces: #ns1
children(#ns2) has found 'node2' -- Its namespaces: #ns2
children(#ns3) has found 'node3' -- Its namespaces: #ns3

-- 
Edit bug report at http://bugs.php.net/?id=41861&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=41861&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=41861&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=41861&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=41861&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=41861&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=41861&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=41861&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=41861&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=41861&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=41861&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=41861&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=41861&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=41861&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=41861&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=41861&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=41861&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=41861&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=41861&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=41861&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=41861&r=mysqlcfg

Reply via email to