note 103769 added to function.readdir
| From: | stuart at horuskol dot net | Date: | Tue, 03 May 2011 05:19:05 +0000 |
| Subject: | note 103769 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179354@lists.php.net to get a copy of this message | ||
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($path)) !== false) {
// do stuff
}
?>
----
Server IP: 117.104.162.229
Probable Submitter: 203.122.234.143 (proxied: 203.122.234.143)
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- https://master.php.net/note/edit/103769
Del: integrated -- https://master.php.net/note/delete/103769/integrated
Del: useless -- https://master.php.net/note/delete/103769/useless
Del: bad code -- https://master.php.net/note/delete/103769/bad+code
Del: spam -- https://master.php.net/note/delete/103769/spam
Del: non-english -- https://master.php.net/note/delete/103769/non-english
Del: in docs -- https://master.php.net/note/delete/103769/in+docs
Del: other reasons-- https://master.php.net/note/delete/103769
Reject -- https://master.php.net/note/reject/103769
Search -- https://master.php.net/manage/user-notes.php