ID:               22883
 Updated by:       [EMAIL PROTECTED]
 Reported By:      stephen at mu dot com dot au
-Status:           Open
+Status:           Wont fix
 Bug Type:         Feature/Change Request
 Operating System: Linux
 PHP Version:      4.3.0
 New Comment:

Your summary is not 100% correct.

feof(NULL) will actually do two things:

1) It will generate an E_WARNING condition stating that the supplied
argument is not a valid stream resource.

2) It will return NULL, not FALSE

This means two things:

1) replacing: (!feof($fp)) with a sctrict check of (feof($fp) ===
false) will be enough to 'fix' your example script.

2) Good coding practices dictate that one should examine the contents
of a variable before using it.

$fp = fopen($filename);
if ($fp) {
  while (!feof($fp)) fread($fp, 1024);
} else {
  echo 'Unable to open file.';
}

Either way, there is no reason to modify this function with a piece of
bloat which performs an otherwise unnecessary operation.


Previous Comments:
------------------------------------------------------------------------

[2003-03-25 17:32:51] stephen at mu dot com dot au

Short code snippet -

$fp = fopen($filename);
while (!feof($fp)) fread($fp, 1024);

Summary -
fopen() requires 2 arguments, not 1 so it returns NULL (this is correct
behavior).

feof($fp) when $fp = NULL returns false. So when using !feof($fp) as a
loop condition, we get an infinite loop (and 2 error messages per
iteration around the loop).

I suggest that the foef() function be modified to return that foef($fp)
is true, not false, when reporting an error with the file handle
resource. This is on the basis that foef($fp) returning false is a
condition for the program to continue reading from $fp (i.e. the file
pointer contains more data - has not reached the end of file).

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=22883&edit=1

Reply via email to