|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80660 FilesystemIterator foreach-loop fails on fuse filesystems
Submitted: 2021-01-22 13:53 UTC Modified: 2024-01-04 20:30 UTC
Avg. Score:2.8 ± 1.1
Reproduced:3 of 4 (75.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: shop1 at mokraemer dot de Assigned:
Status: Open Package: SPL related
PHP Version: 7.4.14 OS: linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: shop1 at mokraemer dot de
New email:
PHP Version: OS:


 [2021-01-22 13:53 UTC] shop1 at mokraemer dot de
As for my testing, FilesystemIterator fails with the foreach loop while the while-next loop works as expected.

Test script:
$iterator = new \FilesystemIterator(
           | \FilesystemIterator::SKIP_DOTS
echo "--while\n";
while($iterator->valid()) {
	echo $iterator->current()."\n";
echo "--for\n";
foreach ($iterator as $entry) {
	echo $entry->getFilename()."\n";

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-30 02:19 UTC] marcelo at ofload dot com
I'm having a similar issue.

In your example, if you don't rewind() it works.
- create the iterator
- while()
- foreach()

But I can also see an issue where if you rewind() before while() it fails.
- create the iterator
- rewind()
- while()

Also, if we do foreach() before while() it fails:
- create the iterator
- foreach()
- rewind()
- while()

In summary, depending if you call rewind() or not calling rewind() it fails for foreach() or while() too.

This is a very awkward bug that is happening in a Docker container with Windows as a Host.
 [2022-08-25 05:38 UTC] staffan at njoy dot fi
I think this is what I'm seeing in docker on windows, I'm using the php:7-fpm-alpine image and it's currently at 7.4.30.

I'm only seeing it if the directory that's being scanned has more than about 50 entries though. It puzzled me greatly why Drupal would fail to identify its modules if the modules directory had a lot of modules but be fine if I moved them around so that no modules directory had more than that. I've only seen this when the modules were on a bind mounted volume.
 [2024-01-04 20:30 UTC]
-Package: *Directory/Filesystem functions +Package: SPL related
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 17:01:29 2024 UTC