ID:               42036
 Updated by:       [EMAIL PROTECTED]
 Reported By:      kraghuba at in dot ibm dot com
-Status:           No Feedback
+Status:           Closed
 Bug Type:         Filesystem function related
 Operating System: RHEL 5
 PHP Version:      5CVS-2007-07-18 (snap)
 Assigned To:      wez
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

The code wasn't checking for EOF.


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

[2007-08-09 01:00:00] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

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

[2007-08-01 10:54:23] [EMAIL PROTECTED]

Wez, better that you decide. ;)

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

[2007-07-31 12:13:05] kraghuba at in dot ibm dot com

I have tried similar stuff on C language and and found that feof
doesn't get changed by using fgetc() on file opened in write only mode.
The documentation of fgetc() for C says that it returns an int or EOF on
end of the file or an *error*. 

I haven't have enough time to look at any other version other than php6
and 5 (:

I think that same thing can be done for php, the application level
error should be reported as false and this should be documented. Even
other wise if you decide to have the EOF as application level error then
it should be documented. 

Sample code that i use for checking it fgetc() on C :
#include <stdio.h>
int main ( void )
{
  FILE *fp;
  char ch;

  fp = fopen("test.txt", "w");
  fwrite("testing", 7, 1, fp);

  rewind(fp);
  printf("\nftell() returns = %d\n", ftell(fp) );
  printf("\nfeof() returns = %s\n", ( feof(fp) ? "true" : "false") );

  // try read
  printf("\nfgets() returns = %d\n", fgetc(fp) );
  printf("\nftell() returns = %d\n", ftell(fp) );
  printf("\nfeof() returns = %s\n", ( feof(fp) ? "true" : "false") );

  fclose(fp);
}

Output:

ftell() returns = 0

feof() returns = false

fgets() returns =-1

ftell() returns = 0

feof() returns = false

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

[2007-07-23 14:47:48] [EMAIL PROTECTED]

Without having had time to dig deeper just yet, if you open for write
only, you shouldn't expect to be able to read.  This application-level
error is reflected as EOF.

So the question becomes, is this behavior different from libc, and did
the php behavior change between releases? (I'm not including PHP 6 in
that, because it is not released yet)

If the latter, we need to fix it, it not, we probably shouldn't fix it
if there's a risk of breaking an app.

I'm leaning towards won't fix; you should open the file as you intend
to use it.

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

[2007-07-23 08:34:56] [EMAIL PROTECTED]

Wez, could you plz comment this?

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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/42036

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

Reply via email to