From:             
Operating system: Debian unstable
PHP version:      5.3.5
Package:          SPL related
Bug Type:         Bug
Bug description:DirectoryIterator isn't iterable with a foreach

Description:
------------
Hello,



DirectoryIterator is iterable in a while but not in a foreach.



This bug is reproductible only on a vboxsf filesystem. I run this script on
Debian sid hosted on Windows XP (NTFS formated hd).



I have no problem when I execute this script on Windows or on a virtual
disk.

Test script:
---------------
<?php

function test_iterator($dirname) {

    $files = array();



    $dir = new DirectoryIterator($dirname);

    while($dir->valid()) {

        $files[] = (string)$dir->current();

        $dir->next();

    }

    return $files;

}



function test_iterator_bug($dirname) {

    $files = array();



    $dir = new DirectoryIterator($dirname);

    foreach($dir as $file) {

        $files[] = (string)$file;

    }

    return $files;

}



echo 'PHP version: ' . phpversion() . "\n\n";

$dirname = dirname(__FILE__);

foreach (array('iterator', 'iterator_bug') as $test_name) {

    echo "--- {$test_name} ---\n";

    $foo = "test_{$test_name}";

    var_dump($foo($dirname));

    echo "\n";

}



Expected result:
----------------
PHP version: 5.3.5-1



--- iterator ---

array(3) {

  [0]=>

  string(1) "."

  [1]=>

  string(2) ".."

  [2]=>

  string(9) "index.php"

}



--- iterator_bug ---

array(3) {

  [0]=>

  string(1) "."

  [1]=>

  string(2) ".."

  [2]=>

  string(9) "index.php"

}



Actual result:
--------------
PHP version: 5.3.5-1



--- iterator ---

array(3) {

  [0]=>

  string(1) "."

  [1]=>

  string(2) ".."

  [2]=>

  string(9) "index.php"

}



--- iterator_bug ---

array(0) {

}

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

Reply via email to