note 103770 deleted from function.readdir by danbrown
| From: | danbrown@php.net | Date: | Tue, 03 May 2011 13:38:58 +0000 |
| Subject: | note 103770 deleted from function.readdir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179363@lists.php.net to get a copy of this message | ||
Note Submitter: stuart at horuskol dot net
----
Looking through the examples, I can't see any that do a simple check on the value of the
directory resource that opendir returns and is subsequently used by readdir.
If opendir returns false, and you simply pass this to the readdir call in the while loop, you will
get an infinite loop.
A simple test helps prevent this:
<?php
$dir = opendir($path);
while ($dir && ($file = readdir($$dir)) !== false) {
// do stuff
}
?>