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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
37 - 4 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 05:01:30 2024 UTC