note 82787 added to function.opendir

From: Date: Fri, 25 Apr 2008 16:23:04 +0000
Subject: note 82787 added to function.opendir
Groups: php.notes 
Request: Send a blank email to php-notes+get-138776@lists.php.net to get a copy of this message
here's a gotcha! If you are using while ($file = readdir($dh)) { echo "$file\n"; } and your script comes across a directory called ./0 (i.e. zero), the expression will evaluate to false, and the loop will end unexpectedly. What you need to do is the following: while (($file = readdir($dh)) !== false) { echo "$file\n"; } closedir($dh); ---- Server IP: 92.48.74.199 Probable Submitter: 217.33.170.226 ---- Manual Page -- http://www.php.net/manual/en/function.opendir.php Edit -- https://master.php.net/note/edit/82787 Del: integrated -- https://master.php.net/note/delete/82787/integrated Del: useless -- https://master.php.net/note/delete/82787/useless Del: bad code -- https://master.php.net/note/delete/82787/bad+code Del: spam -- https://master.php.net/note/delete/82787/spam Del: non-english -- https://master.php.net/note/delete/82787/non-english Del: in docs -- https://master.php.net/note/delete/82787/in+docs Del: other reasons-- https://master.php.net/note/delete/82787 Reject -- https://master.php.net/note/reject/82787 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138776) next »