From: hubert dot roksor at gmail dot com Operating system: PHP version: 5CVS-2007-07-10 (snap) PHP Bug Type: SimpleXML related Bug description: SimpleXML incorrectly registers empty strings as namespaces
Description: ------------ As per XML Namespaces specifications, "The attribute value in a default namespace declaration MAY be empty. This has the same effect, within the scope of the declaration, of there being no default namespace." (source: http://www.w3.org/TR/REC-xml-names/#defaulting) However, when creating elements using an empty string as namespace, SimpleXML seems to register the empty string as a namespace instead of just removing any inherited namespace. In the reproduce code below, we generate an empty tree to which we add a new element "child" in the namespace "http://myns". Then we add an element "grandchild" (whose content will be "hello") to that element using an empty string as namespace so that "grandchild" does not inherit "http://myns" as namespace. Then we attempt to transform the tree using XSLT, and verify grandchild's namespaces with getNamespaces(). Apparently, it is impossible to access "grandchild" in XSL because it belongs to an empty namespace using an empty prefix (as shown with getNamespaces()). Reloading the tree by dumping it as XML then reparsing it with simplexml_load_string() circumvents that bug. Tested on: PHP 5.2.4-dev (cli) (built: Jul 10 2007 00:04:16) libXML Version => 2.6.26 SimpleXML Revision => $Revision: 1.151.2.22.2.32 $ libxslt Version => 1.1.17 Reproduce code: --------------- <?php $xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><root xmlns:myns="http://myns" />'); $grandchild = $xml->addChild('child', null, 'http://myns')->addChild('grandchild', 'hello', ''); $xslt = new XSLTProcessor; $xslt->importStylesheet(simplexml_load_string('<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myns="http://myns"> <xsl:template match="myns:child"> [<xsl:value-of select="grandchild" />] </xsl:template> </xsl:stylesheet>')); echo 'output before reload: ', $xslt->transformToXML($xml), "namespaces: ", print_r($grandchild->getNamespaces(), true); $xml = simplexml_load_string($xml->asXML()); $children = $xml->children('http://myns'); $grandchild = $children[0]->grandchild; echo "\noutput after reload: ", $xslt->transformToXML($xml), "namespaces: ", print_r($grandchild->getNamespaces(), true); ?> Expected result: ---------------- output before reload: <?xml version="1.0"?> [hello] namespaces: Array ( ) output after reload: <?xml version="1.0"?> [hello] namespaces: Array ( ) Actual result: -------------- output before reload: <?xml version="1.0"?> [] namespaces: Array ( [] => ) output after reload: <?xml version="1.0"?> [hello] namespaces: Array ( ) -- Edit bug report at http://bugs.php.net/?id=41947&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41947&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41947&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41947&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41947&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41947&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41947&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41947&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41947&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41947&r=support Expected behavior: http://bugs.php.net/fix.php?id=41947&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41947&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41947&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41947&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41947&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41947&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41947&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41947&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41947&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41947&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41947&r=mysqlcfg
