|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75309 Iterators are no longer alphabetical
Submitted: 2017-10-04 13:33 UTC Modified: 2017-10-05 13:43 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: james at bluebaytravel dot co dot uk Assigned:
Status: Open Package: SPL related
PHP Version: 7.1.10 OS: Ubuntu
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: james at bluebaytravel dot co dot uk
New email:
PHP Version: OS:


 [2017-10-04 13:33 UTC] james at bluebaytravel dot co dot uk
In PHP 7.1.10 iterators are no longer iterating through results alphabetically.

PHP 7.1.8 is the last version I've been able to see the expected result on (I've not been able to test anything later).

In our code, we have a folder with ,php files in there and two sub-folders (Api and Dashboard) containing more .php files. In PHP 7.1.8 the test script iterators through them alphabetically but in PHP 7.1.10 the Api sub-folder is listed at the end of the iterator.

Test script:
$directoryIterator = new RecursiveDirectoryIterator($path);
$routeIterator = new RecursiveIteratorIterator($directoryIterator);
$routes = new RegexIterator($routeIterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-04 13:49 UTC]
-Status: Open +Status: Feedback
 [2017-10-04 13:49 UTC]
What makes you think the order is guaranteed?

I'm pretty certain there is no code inside PHP to sort directory iterators internally, or for any of the other filesystem functions.

The order of directory entries is controller by your underlying operating system, which is free to return whatever order it feels like.
 [2017-10-05 09:59 UTC] james at bluebaytravel dot co dot uk
It's always been in order previously... I can't see an obvious reason as to why Ubuntu would've changed the behaviour? I use Laravel Homestead and am able to go back to a prior version and see the expected results.
 [2017-10-05 10:14 UTC] spam2 at rhsoft dot net
fact is that no documentation says anything about ordering and so you rely on undefined behavior

fact is that readdir() on windows has sorted results and on Linux it don't which proves that php itself never sorted anything which is a good thing because it would waste performance for cases where it don't matter at all
 [2017-10-05 13:43 UTC]
-Status: Feedback +Status: Open -Type: Bug +Type: Documentation Problem
 [2017-10-05 13:43 UTC]
As stated by others: the order of files returned is not guaranteed.

I couldn't find a mention of it after a quick glance at the manual. If it really isn't documented yet it would be nice to mention it somewhere.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jun 14 21:01:30 2024 UTC