ID: 42259 Updated by: [EMAIL PROTECTED] Reported By: jazzslider at gmail dot com -Status: Open +Status: Closed Bug Type: SPL related Operating System: Windows PHP Version: 5.2.4RC1 New Comment:
This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2007-08-09 18:09:03] jazzslider at gmail dot com Description: ------------ I'm getting this error on PHP 5.2.2 and haven't had a chance to upgrade to 5.2.4 yet, but I wanted to mention it anyway since it seems like it would be sort of a niche bug. When iterating over XML using RecursiveIteratorIterator(SimpleXMLIterator(xml)), XPath expressions intended to retrieve a node's ancestors do not retrieve all of them. In the below example, this means that only the immediate parent of the current node can be identified; in other test cases I've run, not even the parent was available. Reproduce code: --------------- $xml = '<xml><fieldset1><field1/><field2/></fieldset1><fieldset2><options><option1/><option2/><option3/></options><field1/><field2/></fieldset2></xml>'; $sxe = new SimpleXMLIterator($xml); $rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::LEAVES_ONLY); foreach ($rit as $child) { $path = ''; $ancestry = $child->xpath('ancestor-or-self::*'); foreach ($ancestry as $ancestor) { $path .= $ancestor->getName() . '/'; } $path = substr($path, 0, strlen($path) - 1); echo count($ancestry) . ' steps: ' . $path . PHP_EOL; } Expected result: ---------------- 3 steps: xml/fieldset1/field1 3 steps: xml/fieldset1/field2 1 steps: xml/fieldset2/options/option1 1 steps: xml/fieldset2/options/option2 1 steps: xml/fieldset2/options/option3 3 steps: xml/fieldset2/field1 3 steps: xml/fieldset2/field2 Actual result: -------------- 2 steps: fieldset1/field1 2 steps: fieldset1/field2 2 steps: options/option1 2 steps: options/option2 2 steps: options/option3 2 steps: fieldset2/field1 2 steps: fieldset2/field2 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42259&edit=1
