Re: Opening and reading director produces random order
| From: | Christoph Becker | Date: | Tue, 09 Dec 2014 20:35:43 +0000 |
| Subject: | Re: Opening and reading director produces random order | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324106@lists.php.net to get a copy of this message | ||
Jeffry Killen wrote:
> On Dec 9, 2014, at 12:13 PM, Ashley Sheridan wrote:
>
>> On 9 December 2014 20:05:42 GMT+00:00, Jeffry Killen
>> <jekillen@prodigy.net> wrote:
>>
>>> @$_dr = opendir($_dir);
>>
>> I believe the natural order of a directory listing on linux is by the
>> internal inode number.
The readdir() documentation[1] states:
| Returns the name of the next entry in the directory. The entries are
| returned in the order in which they are stored by the filesystem.
>> It should be easy though to put the listing
>> results into an array first and then sort that however you wish.
ACK. Or use scandir()[2].
>> Also, one thing you should always avoid is the use of @ to suppress
>> errors. If you think your code will cause an error, code defensively,
>> or at the least use exception handling.
>
> Thank you for the info:
> As far as not using @ to surpress errors, I am also aware of using try
> and catch slowing the code execution down.
AFAIK, the @ operator does also slow down the code.
> I don't want a page with only an error message smeared over it and
> nothing else. So why is it a bad thing?
Because it could hide unexpected notices/warnings. And in a production
environment display_errors is turned off (well, it should be), so you
won't see the error message on the page, anyway.
[1] <http://php.net/manual/en/function.readdir.php>
[2] <http://php.net/manual/en/function.scandir.php>
--
Christoph M. Becker