|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42348 xPath beginning with "//" searches whole document
Submitted: 2007-08-20 10:57 UTC Modified: 2007-08-20 11:27 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: guenther dot stadler at gmx dot net Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: guenther dot stadler at gmx dot net
New email:
PHP Version: OS:


 [2007-08-20 10:57 UTC] guenther dot stadler at gmx dot net
When using // at the beginning of an xpath-query, not only the children of the current SimpleXMLElement are searched (as stated in the manual), but the whole XML document instead.
(So, actually, it might only be a documentation issue...)

If this is expected behaviour, how is one supposed to search all <bar> elements, no whether where they are - but only under the current item (whatever it might be)?

Reproduce code:
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
 <foo id="foo_1">
 <foo id="foo_2">

$xml = new SimpleXMLElement($xmlstr);

$foo_list = $xml->xpath('//foo');
$foo = $foo_list[0]; // now we have the node with id="foo_1"

$bar_list = $foo->xpath('//bar');
foreach($bar_list as $this_bar)
	echo "$this_bar ";

Expected result:
1 2 

Actual result:
1 2 3 4 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-20 11:27 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

Behavior is according to XPath specs:
The SimpleXMLElement used to call the xpath() method is used as the context node.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Feb 26 03:01:33 2024 UTC