|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-07-19 07:59 UTC] m dot philipp at coreto dot de
[2010-07-19 09:09 UTC] david at sickmiller dot com
[2010-10-06 16:13 UTC] bugs dot php dot net at moesen dot nu
[2013-12-03 08:15 UTC] mike@php.net
-Status: Open
+Status: Not a bug
[2013-12-03 08:15 UTC] mike@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 21:00:01 2025 UTC |
Description: ------------ Sometimes the DOMXpath->evaluate() function returns unreliable results. This seems to happen when the document has at least a depth of 3 and selectors are used at multiple levels. There may be other conditions that trigger it; I'm not sure. The test script below is consistently showing errors for me. Test script: --------------- <?php $rawxml = '<?xml version="1.0"?><root><field attr1="val1"><field attr1="val1"/></field></root>'; $rawxpath = "/root[1]/field[@attr1='val1']"; $results = array(); for ($i = 0; $i < 10000; $i++) { $xmlDocument = new DOMDocument(); $xmlDocument->loadXML($rawxml); $xp = new DOMXPath($xmlDocument); $xpr = $xp->evaluate($rawxpath, $xmlDocument->documentElement); if (isset($results[(string) $xpr->length])) $results[(string) $xpr->length]++; else $results[(string) $xpr->length] = 1; } foreach ($results as $matches => $count) printf("In %5d instances, found $matches match(es) for $rawxpath\n", $count); Expected result: ---------------- In 10000 instances, found 1 match(es) for /root[1]/field[@attr1='val1'] Actual result: -------------- The exact numbers seem to vary, but I get roughly this response: In 9924 instances, found 1 match(es) for /root[1]/field[@attr1='val1'] In 76 instances, found 2 match(es) for /root[1]/field[@attr1='val1']