php.net |  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: -
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: shop1 at mokraemer dot de Assigned:
Status: Open Package: *Directory/Filesystem functions
PHP Version: 7.4.14 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: shop1 at mokraemer dot de
New email:
PHP Version: OS:

 

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

Test script:
---------------
<?php
$iterator = new \FilesystemIterator(
	'/fuse-filesystem',
             \FilesystemIterator::CURRENT_AS_SELF
           | \FilesystemIterator::SKIP_DOTS
);
echo "--while\n";
while($iterator->valid()) {
	echo $iterator->current()."\n";
	$iterator->next();
}
$iterator->rewind();
echo "--for\n";
foreach ($iterator as $entry) {
	echo $entry->getFilename()."\n";
}


Expected result:
----------------
--while
.hg
file1.class.php
file2.class.php
--for
.hg
file1.class.php
file2.class.php


Actual result:
--------------
--while
.hg
file1.class.php
file2.class.php
--for


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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.
i.e.
- create the iterator
- while()
- foreach()

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

Also, if we do foreach() before while() it fails:
i.e.
- 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.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu May 13 05:01:24 2021 UTC