|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55700 Disable automatic registration on a DOMXpath object.
Submitted: 2011-09-15 11:16 UTC Modified: 2019-10-05 17:04 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: thomas at weinert dot info Assigned: beberlei (profile)
Status: Closed Package: DOM XML related
PHP Version: 5.3.8 OS:
Private report: No CVE-ID: None
 [2011-09-15 11:16 UTC] thomas at weinert dot info
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:

$dom = new DOMDocument();
  '<foobar><a:foo xmlns:a="urn:a">'.
  '<b:bar xmlns:b="urn:b"/></a:foo>'.
$xpath = new DOMXPath($dom);
// disable automatic namespace registration
$xpath->enableRegisterNodeNS = FALSE;

$context = $dom->documentElement->firstChild;

$xpath->registerNamespace('a', 'urn:b');

Expected result:
string(5) "b:bar" 

Actual result:
string(5) "a:foo"


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-09-15 12:19 UTC]
-Assigned To: +Assigned To: rrichards
 [2011-09-15 12:19 UTC]
hi Rob!

Can you take a look pls? Afaict it is not BC but this behavior never really works 
 [2011-09-15 12:24 UTC]
See as well
 [2011-09-23 15:07 UTC] thomas at weinert dot info
This should not brake BC because the default value of the option would still be TRUE. If the developer does not set the option to FALSE it will still show the same unpredictable behavior like before. 

The idea is to make a transition from automatic to manual registration less painful and more secure.

But I am not sure about the evaluate()/query() parameter. It would get at least more complex. (NULL = default, use option value)
 [2014-08-19 10:08 UTC]
-Assigned To: rrichards +Assigned To: daverandom
 [2017-10-24 07:11 UTC]
-Status: Assigned +Status: Open -Assigned To: daverandom +Assigned To:
 [2019-09-23 20:47 UTC]
The following pull request has been associated:

Patch Name: ext/dom: Add global registerNodeNS flag on DOMXPath.
On GitHub:
 [2019-10-05 17:04 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: beberlei
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Sep 22 15:01:24 2023 UTC