php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4044 while loop continues infinitely where it should cease
Submitted: 2000-04-04 23:48 UTC Modified: 2000-04-05 00:17 UTC
From: marek at welshdragon dot com Assigned:
Status: Closed Package: Other
PHP Version: 4.0 Release Candidate 1 OS: linux 2.2.14
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marek at welshdragon dot com
New email:
PHP Version: OS:

 

 [2000-04-04 23:48 UTC] marek at welshdragon dot com
$DH = opendir(".");
while (print(readdir($DH)));
this continues until the script times out

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-04-05 00:17 UTC] torben at cvs dot php dot net
It is not an error under PHP to print a false value, which is all that the 
print() statement here would be doing once readdir() started returning
false. Therefore, the loop continues. For instance, the following bit of
code should never print 'Didn't print false':

<?php
if ( print( false ) ) {
   echo "Printed false<br>\n";
} else {
   echo "Didn't print false<br>\n";
}
?>

The following should do what you want:

<?php
$DH = opendir(".");
while ( $dir_entry = readdir( $DH ) ) {
   print "$dir_entry<br>\n";
}
?>

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 06:01:32 2025 UTC