ID: 48130 Updated by: j...@php.net Reported By: richard dot piatkowski at meap dot de -Status: Open +Status: Feedback Bug Type: SPL related Operating System: Windows XP PHP Version: 5.2.9 New Comment:
What exactly is the expected and what is actual output? Also, reproduce scripts should be as short as possible, start with <?php and end with ?> Previous Comments: ------------------------------------------------------------------------ [2009-05-02 12:30:33] richard dot piatkowski at meap dot de Description: ------------ It is impossible to iterate through the children of a tree structure with a RecursiveRegexIterator combined with a RecursiveIteratorIterator. It only works when using the regex /A/, /r/ or /y/, because this characters are in the word "Array". See line 74 of ext/spl/internal/regexiterator.inc: $subject = ($this->flags & self::USE_KEY) ? $this->key : $this->current; When iterating over an array of arrays (e.g. array[3] in the above example) "$subject" gets the value of "$this->current". In the case of an arraym this value will be "Array". This explains, why in the above example the regex "/y/" works, while "/v/" is not. "/y/" finds a match in "Array". The methode "accept()" of the RegexIterator-Object should first check, whether an array has children, when working on nested arrays. If a nested array is found, there is no sense in matching the regex against "Array". Possible workaround could be adding the following lines above line 74 in ext/spl/internal/regexiterator.inc: if (is_array($subject) == true) { return true; } Reproduce code: --------------- $array = array(); $array[0] = 'one'; $array[1] = 'two'; $array[2] = 'three'; $array[3] = array('four', 'five', 'xxx', 'yyy'); $array[4] = 'six'; $array[5] = 'seven'; // Correct output: // "yyy - " $recArrayIt = new RecursiveArrayIterator($array); $recRegexIt = new RecursiveRegexIterator($recArrayIt, '/y/'); $recItIt = new RecursiveIteratorIterator($recRegexIt); foreach($recItIt as $element) { echo $element.' - '; } // Wrong output: "seven - " // Should be : "five - seven -" $recArrayIt = new RecursiveArrayIterator($array); $recRegexIt = new RecursiveRegexIterator($recArrayIt, '/v/'); $recItIt = new RecursiveIteratorIterator($recRegexIt); foreach($recItIt as $element) { echo $element.' - '; } ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=48130&edit=1