ID:               41763
 Updated by:       [EMAIL PROTECTED]
 Reported By:      kraghuba at in dot ibm dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Documentation problem
 Operating System: linux, windows
 PHP Version:      Irrelevant
 New Comment:

The sample code is clear and my example shows you what's happening.
ftell() tells you the position from the opening point. Append mode's
opening point is at the end of the file so initial ftell() tells
correctly 0.


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

[2007-08-17 07:15:55] kraghuba at in dot ibm dot com

The guess, the sample code given in the defect didn't make the point
clear. Here is the code that would

<?php
  // create a file first
  file_put_contents("test.txt", "Testing fopen with a mode");
  

  // now open the file in append mode and check the initial
  // location of file pointer 
  $fp = fopen ("test.txt", "a");
  
  // check the position of the fp
  // expected same as return value of filesize("test.txt"), as per the
doc
  // but it returns 0 which is the right behavior.
  var_dump( ftell($fp) );  
  
  fclose($fp);
?>

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

[2007-08-16 13:50:04] [EMAIL PROTECTED]

fopen(, "a") works as described but ftell() tells offset since
opening:
<?php
echo filesize("x") . " ";
$fp = fopen("x", "a");
echo ftell($fp) . " ";
fwrite($fp, "a");
echo ftell($fp);
?>
outputs e.g. 5 0 1.

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

[2007-06-21 12:54:29] kraghuba at in dot ibm dot com

Description:
------------
The current documentation of fopen for append mode doesn't state
clearly where the file pointer is set initally. The doc says :
"In a mode : Open for writing only; place the file pointer at the end
of the file. If the file does not exist, attempt to create it.".

But in reality the file pointer is set to 0, the file position is moved
to end of file before any write operation.

Please modify the document to make this clear. 

I also noticed that in response to following defect this was explained
: "Bug #15528: ftell does not work consistently"


Reproduce code:
---------------
<?php
$fp = fopen(__FILE__, "a"); 
var_dump($fp);
var_dump( ftell($fp) );   // ftell should return the size of the file 
fclose($fp);
?>


Expected result:
----------------
C:\workdir\test>php fopen.php
resource(5) of type (stream)
int(0)

Actual result:
--------------
C:\workdir\test>php fopen.php
resource(5) of type (stream)
int(0)


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


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

Reply via email to