Re: Opening and reading director produces random order

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux