Edit report at http://bugs.php.net/bug.php?id=54256&edit=1
ID: 54256 Comment by: gege2061 at homecomputing dot fr Reported by: gege2061 at homecomputing dot fr Summary: DirectoryIterator isn't iterable with a foreach Status: Feedback Type: Bug Package: SPL related Operating System: Debian unstable PHP Version: 5.3.5 Block user comment: N Private report: N New Comment: The problem is reproducible with php5.3-201103170730 Previous Comments: ------------------------------------------------------------------------ [2011-03-16 21:13:31] johan...@php.net Please try using this snapshot: http://snaps.php.net/php5.3-latest.tar.gz For Windows: http://windows.php.net/snapshots/ Works perfectly for me. "PHP version: 5.3.5-1" is none of our version numbers. MAybe your distribution has patched this somehow. Please test our version or talk to the distributor. ------------------------------------------------------------------------ [2011-03-15 15:23:26] gege2061 at homecomputing dot fr 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 this bug report at http://bugs.php.net/bug.php?id=54256&edit=1