php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24627 feof always returns false
Submitted: 2003-07-12 18:07 UTC Modified: 2003-07-13 03:45 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: duerra at yahoo dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.3RC1 OS: XP Pro
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: duerra at yahoo dot com
New email:
PHP Version: OS:

 

 [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).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-12 18:21 UTC] b_ulrich at t-online dot de
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.
 [2003-07-12 18:28 UTC] elmicha@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Yes, b_ulrich is right.
 [2003-07-12 18:31 UTC] duerra at yahoo dot com
This always worked correct in previous versions of PHP.  It wasn't until the move to 4.3.3RC1 (from 4.3.2) that I had this infinite looping problem.
 [2003-07-12 22:39 UTC] duerra at yahoo dot com
php.net's own manual shows that this should work.  I'm not reading the file, but rather just gathering a count of each line.  As I stated, this has always worked in previous versions of PHP, and is also many tutorials and books, including "PHP and MySQL Web Development" (as I am looking at the example right now) have shown an example almost identical to what I've posted here on how to do such looping and counting.  I believe that the file pointer not moving is exactly the problem (please correct me if I'm wrong).  Is that not a bug, and if not, what has changed between 4.3.2 and 4.3.3 that I have not noticed??  I see nothing of reference in the change log for 4.3.3
 [2003-07-12 22:42 UTC] sniper@php.net
There must have been some bug in previous versions,
feof() never moves the file pointer so you end up in endless loop, of course. (I don't know where in the manual it's said it moves the file pointer..)

 [2003-07-12 22:45 UTC] duerra at yahoo dot com
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...)
 [2003-07-12 22:48 UTC] sniper@php.net
Don't mix user added comments to real documentation..

 [2003-07-12 22:51 UTC] duerra at yahoo dot com
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
 [2003-07-12 22:54 UTC] sniper@php.net
It has ALWAYS been the requirement. Some buffer sizes and so were adjusted in 4.3.2 (or something alike, can't remember exactly what it was right now) which made it LOOK like it worked for you.

 [2003-07-13 03:45 UTC] wez@php.net
If you don't read from the pointer, the position never moves and thus never reaches the end of file.
This current behaviour is the intended behaviour; if it worked before, it was a bug that you should consider fixed.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 15:01:30 2024 UTC