From:             
Operating system: Cent OS 5
PHP version:      5.2.13
Package:          DOM XML related
Bug Type:         Bug
Bug description:XPath returns inconsistent results

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 bug report at http://bugs.php.net/bug.php?id=52373&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=52373&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=52373&r=trysnapshot53
Try a snapshot (trunk):              
http://bugs.php.net/fix.php?id=52373&r=trysnapshottrunk
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=52373&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=52373&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=52373&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=52373&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=52373&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=52373&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=52373&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=52373&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=52373&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=52373&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=52373&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52373&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52373&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=52373&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=52373&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=52373&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=52373&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=52373&r=mysqlcfg

Reply via email to