Edit report at http://bugs.php.net/bug.php?id=52373&edit=1
ID: 52373 User updated by: david at sickmiller dot com Reported by: david at sickmiller dot com Summary: XPath returns inconsistent results Status: Open Type: Bug Package: DOM XML related Operating System: Cent OS 5 PHP Version: 5.2.13 New Comment: I wonder if this may be related to the libxml2 library. I am using v2.6.26-2.1.2.8 from the CentOS distribution. Previous Comments: ------------------------------------------------------------------------ [2010-07-19 07:59:35] m dot philipp at coreto dot de Cannot repeat with php 5.3.2. All test runs resulted in: "In 10000 instances, found 1 match(es) for /root[1]/fie...@attr1='val1']" ------------------------------------------------------------------------ [2010-07-19 01:37:51] david at sickmiller dot com 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]/fie...@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]/fie...@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]/fie...@attr1='val1'] In 76 instances, found 2 match(es) for /root[1]/fie...@attr1='val1'] ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52373&edit=1