php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45634 DirectoryIterator default sorting error
Submitted: 2008-07-26 20:51 UTC Modified: 2008-07-27 03:28 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 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-26 20:51 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:
----------------
[root@example fox]# ls -l
total 272
-rw-r--r-- 1 nobody nobody 8855 2007-10-28 13:21 dance_L.gif
-rw-r--r-- 1 nobody nobody 8846 2007-10-28 13:21 dance_R.gif
-rw-r--r-- 1 nobody nobody 9880 2007-10-28 13:21 enter_L.gif
-rw-r--r-- 1 nobody nobody 9852 2007-10-28 13:21 enter_R.gif
-rw-r--r-- 1 nobody nobody 8186 2007-10-28 13:21 growl_L.gif
-rw-r--r-- 1 nobody nobody 8173 2007-10-28 13:21 growl_R.gif
-rw-r--r-- 1 nobody nobody 7299 2007-10-28 13:21 headstand_L.gif
-rw-r--r-- 1 nobody nobody 7328 2007-10-28 13:22 headstand_R.gif
-rw-r--r-- 1 nobody nobody 7464 2007-10-28 13:21 hide_L.gif
-rw-r--r-- 1 nobody nobody 7479 2007-10-28 13:21 hide_R.gif
-rw-r--r-- 1 nobody nobody 7924 2007-10-28 13:21 laugh_L.gif
-rw-r--r-- 1 nobody nobody 7957 2007-10-28 13:21 laugh_R.gif
-rw-r--r-- 1 nobody nobody 8138 2007-10-28 13:22 lay_L.gif
-rw-r--r-- 1 nobody nobody 8131 2007-10-28 13:22 lay_R.gif
-rw-r--r-- 1 nobody nobody 5822 2007-10-28 13:21 mad_L.gif
-rw-r--r-- 1 nobody nobody 5836 2007-10-28 13:21 mad_R.gif
-rw-r--r-- 1 nobody nobody 8557 2007-10-28 13:24 music_L.gif
-rw-r--r-- 1 nobody nobody 8533 2007-10-28 13:24 music_R.gif
-rw-r--r-- 1 nobody nobody 8061 2007-10-28 13:22 nuzzle_L.gif
-rw-r--r-- 1 nobody nobody 8079 2007-10-28 13:22 nuzzle_R.gif
-rw-r--r-- 1 nobody nobody 7426 2007-10-28 13:22 rollover_L.gif
-rw-r--r-- 1 nobody nobody 7402 2007-10-28 13:22 rollover_R.gif
-rw-r--r-- 1 nobody nobody 6077 2007-10-28 13:22 sad_L.gif
-rw-r--r-- 1 nobody nobody 6060 2007-10-28 13:22 sad_R.gif
-rw-r--r-- 1 nobody nobody 8407 2007-10-28 13:26 sit_L.gif
-rw-r--r-- 1 nobody nobody 8424 2007-10-28 13:26 sit_R.gif
-rw-r--r-- 1 nobody nobody 5478 2007-10-28 13:22 sleep_L.gif
-rw-r--r-- 1 nobody nobody 5499 2007-10-28 13:22 sleep_R.gif
-rw-r--r-- 1 nobody nobody 7976 2007-10-28 13:22 sprawl_L.gif
-rw-r--r-- 1 nobody nobody 7957 2007-10-28 13:22 sprawl_R.gif
[root@example fox]#

Actual result:
--------------
[root@example skel]# php ./test.php
.
..
laugh_L.gif
laugh_R.gif
sprawl_L.gif
sprawl_R.gif
music_L.gif
music_R.gif
dance_L.gif
dance_R.gif
lay_L.gif
lay_R.gif
sad_L.gif
sad_R.gif
nuzzle_L.gif
growl_L.gif
nuzzle_R.gif
growl_R.gif
headstand_L.gif
headstand_R.gif
sit_L.gif
sit_R.gif
rollover_L.gif
rollover_R.gif
sleep_L.gif
sleep_R.gif
enter_L.gif
mad_L.gif
enter_R.gif
mad_R.gif
hide_L.gif
hide_R.gif
[root@example skel]#

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-27 03:28 UTC] helly@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

It does not help making the wrong bug entry several times. Instead you do cost us very precious time. Guess we have a life too.

Duplicate of #45505: \"DirectoryIterator default sorting error\" entered by same person.

Read: the file system is usually not sorted. Now, while many programs that do display fs entries sort before displaying, SPLs classes do not as that would mean a major slow down. That said, if you need sorting, you need to do it yourself.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 16:01:37 2025 UTC