php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45505 DirectoryIterator default sorting error
Submitted: 2008-07-13 23:25 UTC Modified: 2008-07-14 14:22 UTC
From: jcknight at gmail dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.2.6 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.
Password:
Status:
Package:
Bug Type:
Summary:
From: jcknight at gmail dot com
New email:
PHP Version: OS:

 

 [2008-07-13 23:25 UTC] jcknight at gmail dot com
Description:
------------
The DirectoryIterator class does not iterate the directory how it is organized on the file system.

Reproduce code:
---------------
<?php

$dir = new DirectoryIterator(".");

foreach($dir as $file) {
    echo $file->current() ."\n";
}

?>

Expected result:
----------------
.
..
enter_L.gif
enter_R.gif
mad_L.gif
mad_R.gif

Actual result:
--------------
.
..
enter_L.gif
mad_L.gif
enter_R.gif
mad_R.gif

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-14 09:52 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

There is no sorting guaranteed and the files are returned in the order the operating system provides. 
 [2008-07-14 14:22 UTC] jcknight at gmail dot com
That is the problem, as it does not return the files in the order that the operating system provides.  In the file system, the order is:

enter_L.gif
enter_R.gif
mad_L.gif
mad_R.gif

but the DirectoryIterator provides the files as

enter_L.gif
mad_L.gif
enter_R.gif
mad_R.gif
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 02:01:28 2024 UTC