php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31435 Readdir give unsorted file list output
Submitted: 2005-01-06 23:44 UTC Modified: 2005-01-07 02:21 UTC
From: info at rustelekom dot biz Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 4.3.10 OS: Linux 2.6.9-1.6_FC2smp
Private report: No CVE-ID: None
 [2005-01-06 23:44 UTC] info at rustelekom dot biz
Description:
------------
Hello,

On other system (with Fedora core 1 kernel version) same code give us file and directory list result sorted by created time (so, file created last - also showed as last in output list), but on this system we have other result and it is looks as unsorted (or sorted not by file created time in other words). On both system we use same locale (koi8r) and filesystem type (ext3). 

Sincerely Yours 
Dima Ivanov

Reproduce code:
---------------
<?php
// Note that !== did not exist until 4.0.0-RC2


if ($handle = opendir('./')) {
   echo "Directory handle: $handle<br>";
   echo "Files:<br>";

   /* This is the correct way to loop over the directory. */
   while (false !== ($file = readdir($handle))) {
       echo "$file<br>";
   }

   /* This is the WRONG way to loop over the directory. */
/*   while ($file = readdir($handle)) {
       echo "$file\n";
   } */

   closedir($handle);
}
?>


Expected result:
----------------
Fedora 1 system

Directory handle: Resource id #2
Files:
.
..
SmallNuke_v1.zip
SmallNuke_v1
blocks
images
bandmin-1.6.tar.gz
includes
language
modules
themes
admin
robots.txt
modules.php
.htaccess
header.php
footer.php
index.php
mainfile.php
order
cgi-bin
test.php
myLogs
sql
spaw
banners
forum.sql
header.php.bak
eurodns.html
banners.php
.htaccess.bak
footer.php.bak
mainfile.php.bak
index.html.old
api
login
order.php
gate-order.inc.php
rupay.php
suspended.page
index.html
index.php.old
.htaccess.old
history  < - this is file which newly created


Actual result:
--------------
Fedora 2 system

Directory handle: Resource id #2
Files:
auto.php
auto_ind.php
pictures
search.php
damp
.
sale.php
.htaccess
style
sale_ind.php
admin
test.php   < - this is file which newly created
images
rasdel_ind.php
page.php
rasdel.php
include
..
index.php
logo.swf
description.php
reference.php
print.php
cgi-bin
order.php


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-07 02:21 UTC] tony2001@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

See http://php.net/readdir :
"The filenames are returned in the order in which they are stored by the filesystem."
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC