|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-06-21 12:54 UTC] 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) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 01:00:01 2025 UTC |
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.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); ?>