Bug #54256 [Opn->Fbk]: DirectoryIterator isn't iterable with a foreach
| From: | johannes@php.net | Date: | Wed, 16 Mar 2011 20:13:33 +0000 |
| Subject: | Bug #54256 [Opn->Fbk]: DirectoryIterator isn't iterable with a foreach | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-159530@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54256&edit=1
ID: 54256
Updated by: johannes@php.net
Reported by: gege2061 at homecomputing dot fr
Summary: DirectoryIterator isn't iterable with a foreach
-Status: Open
+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:
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.
Previous Comments:
------------------------------------------------------------------------
[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