php.net |  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
Description:
------------
---
From manual page: http://www.php.net/function.scandir
---

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 
and SORT_DESCENDING.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-26 10:43 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: aharvey
 [2010-11-26 10:43 UTC] aharvey@php.net
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] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&revision=305765
Log: Implemented FR #53407 (make scandir()'s directory sorting optional).
 [2010-11-26 10:53 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2010-11-26 10:53 UTC] aharvey@php.net
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
http://snaps.php.net/.
 
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
SCANDIR_SORT_ASCENDING, SCANDIR_SORT_DESCENDING and SCANDIR_SORT_NONE.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC