From: Operating system: PHP version: 5.3.8 Package: DOM XML related Bug Type: Feature/Change Request Bug description:Disable automatic registration on a DOMXpath object.
Description: ------------ DOMXpath currently registers namespaces of the current context or the document element automatically. This results in broken and inconsistent results (Bug #49490). An argument has been added to evaluate() and query() to change this behavior. The current situation is that the argument and the context argument has ALWAYS to be used to have predictable results. A better way would be an option on the DOMXpath object. An option would not only mean less code, it will also allow to just change one part (initialization of ones DOMXpath instance), without the need to modify all occurrences evaluate()/query() in existing source. Test script: --------------- <?php $dom = new DOMDocument(); $dom->loadXML( '<foobar><a:foo xmlns:a="urn:a">'. '<b:bar xmlns:b="urn:b"/></a:foo>'. '</foobar>' ); $xpath = new DOMXPath($dom); // disable automatic namespace registration $xpath->enableRegisterNodeNS = FALSE; $context = $dom->documentElement->firstChild; $xpath->registerNamespace('a', 'urn:b'); var_dump( $xpath->evaluate( 'descendant-or-self::a:*', $context )->item(0)->tagName ); ?> Expected result: ---------------- string(5) "b:bar" Actual result: -------------- string(5) "a:foo" -- Edit bug report at https://bugs.php.net/bug.php?id=55700&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55700&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55700&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55700&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=55700&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55700&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=55700&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=55700&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=55700&r=needscript Try newer version: https://bugs.php.net/fix.php?id=55700&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=55700&r=support Expected behavior: https://bugs.php.net/fix.php?id=55700&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=55700&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=55700&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=55700&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55700&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=55700&r=dst IIS Stability: https://bugs.php.net/fix.php?id=55700&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=55700&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=55700&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=55700&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=55700&r=mysqlcfg