|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-07-12 18:07 UTC] duerra at yahoo dot com
Description:
------------
In PHP 4.3.3RC1, feof (Windows) always returns false in the code provided below, and goes into an endless loop.
Reproduce code:
---------------
$count = 0;
if ($handle = opendir("./"))
{
while (false !== ($file = readdir($handle)))
{
if(!is_dir($file) AND $file != '.' AND $file !='..' AND $file !='default' AND (strstr($file, ".php") OR strstr($file, ".htm") OR strstr($file, ".txt")))
{
if(!$open = fopen($file, "r"))
{
echo "Could Not Open File";
exit;
}
while(!feof($open))
{
$count++;
}
fclose($open);
}
}
}
echo $count;
Expected result:
----------------
123456
(or another number)
Actual result:
--------------
Infinite loop once a file is opened (I cut out the test code that I used to verify that it's actually a bug in order to stay within the 20 line limit).
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 20:00:01 2025 UTC |
Your example works correct: while(!feof($open)) { $count++; } must be an endless loop because the filepointer never moves. Maybe you should do an fread($open,1024); inside the while loop. Or what ever you want to count.Just a comment from the "feof" reference, as a basic point: if ($fp = fopen($filename, 'r')) { while (!feof($fp)) { // ... } } That's exactly what I'm doing here (though the stating of the file pointer not moving is not explicitly stated, this is shown as working to a level that I have attempted to code...)Sorry. Here's from the documentation on "fgets()" $handle = fopen ("/tmp/inputfile.txt", "r"); while (!feof ($handle)) { $buffer = fgets($handle, 4096); echo $buffer; } fclose ($handle); In essence, what was being done instead of the line beginning with "$buffer=", was "$count++". This this then a requirement now in 4.3.3 that a line is actually retrieved for the file pointer to move? If so, I'll quit nagging you all =P