From:             
Operating system: ubuntu
PHP version:      5.3SVN-2011-07-16 (snap)
Package:          SimpleXML related
Bug Type:         Feature/Change Request
Bug description:missing a way to know if namespace was declared on current node

Description:
------------
---
>From manual page:
http://www.php.net/simplexmlelement.getdocnamespaces%23Voir%20aussi
---


There is no way to know when you're on a SimpleXMLElement, if there were a
new namespace declared on current node. 

It's due to getDocNamespaces or getNamespaces returning xmlns status for
all the document or document root only.

It's conform to what is described in the documentation but as user we may
expect a different behavior.

Test script:
---------------
<?php
//phpinfo();

$x = new SimpleXMLElement(
'<?xml version="1.0" standalone="yes"?>
<people xmlns:p="http://example.org/p"; >
    <person id="1" xmlns:t="http://example.org/t"; >
                <name>John Doe</name>
        </person>
    <person id="2">Susie Q. Public</person>
    <o>
                <div>jdslkfjsldk jskdfjsmlkjfkldjkjflskj kljfslkjf sldk</div>
        </o>
</people>');
//echo '<pre>',$x->asXML(),'</pre>';
echo "\n<br>recursive: <br>\n";
//$tmp = $x->getNamespaces(true) ;
//var_dump($tmp);
$tmp = $x->getDocNamespaces(true) ;
var_dump($tmp);
echo "\n<br>\n";
//$tmp = $x->person[0]->getNamespaces(true) ;
//var_dump($tmp);
$tmp = $x->person[0]->getDocNamespaces(true) ;
var_dump($tmp);
echo "\n<br>\n";
//$tmp = $x->person[1]->getNamespaces(true) ;
//var_dump($tmp);
$tmp = $x->person[1]->getDocNamespaces(true) ;
var_dump($tmp);
*/
echo "\n<br>non recursive: <br>\n";
//$tmp = $x->getNamespaces(false) ;
//var_dump($tmp);
$tmp = $x->getDocNamespaces(false) ;
var_dump($tmp);
echo "\n<br>\n";
//$tmp = $x->person[0]->getNamespaces(false) ;
//var_dump($tmp);
$tmp = $x->person[0]->getDocNamespaces(false) ;
var_dump($tmp);
echo "\n<br>\n";
//$tmp = $x->person[1]->getNamespaces(false) ;
//var_dump($tmp);
$tmp = $x->person[1]->getDocNamespaces(false) ;
var_dump($tmp);



Expected result:
----------------
if we were able to provide namespace declare only on current node instead
of root node, the function will provide the following result

recursive:
array(2) { ["p"]=> string(20) "http://example.org/p"; ["t"]=> string(20)
"http://example.org/t"; }
array(1) { ["t"]=> string(20) "http://example.org/t"; }
array(0) {  }
non recursive:
array(1) { ["p"]=> string(20) "http://example.org/p"; }
array(1) { ["t"]=> string(20) "http://example.org/t"; }
array(0) {  } 



Actual result:
--------------
recursive:
array(2) { ["p"]=> string(20) "http://example.org/p"; ["t"]=> string(20)
"http://example.org/t"; }
array(2) { ["p"]=> string(20) "http://example.org/p"; ["t"]=> string(20)
"http://example.org/t"; }
array(2) { ["p"]=> string(20) "http://example.org/p"; ["t"]=> string(20)
"http://example.org/t"; }
non recursive:
array(1) { ["p"]=> string(20) "http://example.org/p"; }
array(1) { ["p"]=> string(20) "http://example.org/p"; }
array(1) { ["p"]=> string(20) "http://example.org/p"; } 

-- 
Edit bug report at https://bugs.php.net/bug.php?id=55218&edit=1
-- 
Try a snapshot (PHP 5.2):            
https://bugs.php.net/fix.php?id=55218&r=trysnapshot52
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=55218&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=55218&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=55218&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=55218&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=55218&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=55218&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=55218&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=55218&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=55218&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=55218&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=55218&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=55218&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=55218&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=55218&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55218&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=55218&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=55218&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=55218&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=55218&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=55218&r=mysqlcfg
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=55218&r=trysnapshot54

Reply via email to