|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-03-15 15:23 UTC] 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) {
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 08:00:01 2025 UTC |
I have the same issue, but using Parallels on a OS X. I'm running a virtualized Debian 7, PHP 5.4.4-14+deb7u5 as my dev server. The volume is mounted as a Parallels shared folder, in /media/psf/... I have tested this script: ----------------- <?php $iterador = new RecursiveDirectoryIterator( __DIR__ . '/t1/'); foreach ($iterador as $file) { var_dump($file); } ----------------- If the script is inside the shared folder, the result is a blank page. If I execute the script in a not shared folder, a native linux path, it shows an iterator for each dir content.Debian under parallels on MacOS. The same problem: DirectoryIterator return nothing on mounted shared filders foreach (new DirectoryIterator('/media/psf/Web/') as $fileInfo) { echo $fileInfo->getFilename() . "<br>\n"; }