Bug #54256 [NEW]: DirectoryIterator isn't iterable with a foreach

From: Date: Tue, 15 Mar 2011 14:23:27 +0000
Subject: Bug #54256 [NEW]: DirectoryIterator isn't iterable with a foreach
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-159488@lists.php.net to get a copy of this message
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

« previous php.bugs (#159488) next »