|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53407 make scandir()'s directory sorting optional
Submitted: 2010-11-25 21:20 UTC Modified: 2010-11-26 10:53 UTC
From: stolen dot data dot net at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: Directory function related
PHP Version: 5.3.3 OS: applies to all (OpenBSD for me)
Private report: No CVE-ID: None
 [2010-11-25 21:20 UTC] stolen dot data dot net at gmail dot com
From manual page:

Currently, scandir() commits some "userland villainry" by enforcing alphanumerical 
sorting of the directory entries it pulls. In some cases I needed a "natural" 
order of the entries in a directory. In another more obvious case, scandir() 
created notable CPU overhead from always sorting entries in a rather huge 
directory that was frequently read in the application. I had to go back to PHP4's 
opendir/readdir to solve the problem.

I'd like to suggest that scandir() gets new constants introduced to $sorting_order 
in order to make the sorting optional: something like SORT_NONE, SORT_ASCENDING 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-26 10:43 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: aharvey
 [2010-11-26 10:43 UTC]
This looks safe enough to implement on trunk: a Google Code Search
returns no instances of a value other than 0 or 1 being used as
the second parameter to scandir(), so I think as long as we document
this in the UPGRADING file, this should be OK.
 [2010-11-26 10:52 UTC]
Automatic comment from SVN on behalf of aharvey
Log: Implemented FR #53407 (make scandir()'s directory sorting optional).
 [2010-11-26 10:53 UTC]
-Status: Assigned +Status: Closed
 [2010-11-26 10:53 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Implemented on trunk, although I've prefixed the constants with
SCANDIR_ to match our usual constant naming a bit better, hence
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 15:01:39 2024 UTC