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

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.


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

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

Wez, could you plz comment this?

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

[2007-07-21 05:55:08] kraghuba at in dot ibm dot com

This defect is also applicable to the function fgets().

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

[2007-07-18 16:48:08] kraghuba at in dot ibm dot com

Description:
------------
fgetc() sets the end of the file flag to ture when reading from a file
which opened in write only mode.

This failure is applicable on php5 and php6

php version:
PHP 6.0.0-dev (cli) (built: Jul 18 2007 20:53:03) (GCOV)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2007 Zend Technologies

&
PHP 5.2.4-dev (cli) (built: Jul 18 2007 20:49:53) (GCOV)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

OS : RHEL 5
configure setup:
  ./configure --enable-gcov

Reproduce code:
---------------
<?php
  $fp = fopen("test.txt", "w");
  var_dump( fwrite($fp, "Text") );

  // rewind the file pointer to begining
  var_dump( rewind($fp) );
  var_dump( ftell($fp) );
  var_dump( feof($fp) );

  // try to read
  var_dump( fgetc($fp) );
  var_dump( ftell($fp) );
  var_dump( feof($fp) );

  fclose($fp);
  unlink("test.txt");
?>

Expected result:
----------------
output - php5:
--------------
int(4)
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)

output - php6:
--------------
int(4)
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(false)

Actual result:
--------------
output - php5:
--------------
int(4)
bool(true)
int(0)
bool(false)
bool(false)
int(0)
bool(true)

output - php6:
--------------
int(4)
bool(true)
int(0)
bool(false)
string(1) ""
int(0)
bool(true)

output on php6 when run using run-test.php :
int(4)
bool(true)
int(0)
bool(false)
string(1) "ΓΏ"
int(0)
bool(true)


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


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

Reply via email to