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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: xutian at mail dot transfar dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 09:01:26 2025 UTC