php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3699 function readdir() error
Submitted: 2000-03-02 03:15 UTC Modified: 2000-05-22 15:34 UTC
From: xutian at mail dot transfar dot com Assigned:
Status: Closed Package: Parser error
PHP Version: 3.0.14 OS: RedHat Linux 6.0
Private report: No CVE-ID: None
 [2000-03-02 03:15 UTC] xutian at mail dot transfar dot com
look at the below code:

<?
$handle=opendir('/home/txt/'); 
$i=0;
while ($file = readdir($handle)) { 
    if ($file != "." && $file != ".." && $file !="0") { 
        echo $file."<br>";
        $i++; 
    } 
}
closedir($handle); 
?>

if we have a file named 0 in dir "/home/txt/" and then we creat some other files, the files' list in html will not include files last created.
i think maybe readdir return 0 when it get file who's name equal 0.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-05-22 15:34 UTC] hholzgra at cvs dot php dot net
yes, "0" evaluates to false so the loop is terminated

try 

while (""!=($file = readdir($handle))) 

instead, that will do

(bug closed until someone comes up with a filesystem 
where a filename may be all empty)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC