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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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

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 02:01:31 2024 UTC