note 103771 added to function.readdir

From: Date: Tue, 03 May 2011 05:20:39 +0000
Subject: note 103771 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-179356@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($dir)) !== 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/103771 Del: integrated -- https://master.php.net/note/delete/103771/integrated Del: useless -- https://master.php.net/note/delete/103771/useless Del: bad code -- https://master.php.net/note/delete/103771/bad+code Del: spam -- https://master.php.net/note/delete/103771/spam Del: non-english -- https://master.php.net/note/delete/103771/non-english Del: in docs -- https://master.php.net/note/delete/103771/in+docs Del: other reasons-- https://master.php.net/note/delete/103771 Reject -- https://master.php.net/note/reject/103771 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179356) next »