ID:               43729
 Updated by:       [EMAIL PROTECTED]
 Reported By:      rc at opelgt dot org
-Status:           Open
+Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: Mac OS 10.4.11
 PHP Version:      4.4.7
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Sorry, but this is expected behaviour. filesize caches the size (in
that case 4). You write to byte 5 and 6 when doing fwrite($dh, $str2)
bust just read bye 0 to 4 when doing the last fread before cleaning the
cache.


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

[2008-01-02 11:22:16] rc at opelgt dot org

Description:
------------
Although the pointer is at position 0 and filesize is cached with the 
value of 4 fread reads nothing.

A clearstatcache is necessary for fread to operate correct.

Reproduce code:
---------------
<?php
$str1 = '1234';
$str2 = '56';
$datei = 'test.txt';

$dh = fopen ($datei,"w");
fwrite($dh, $str1);
fclose($dh);

$dh = fopen ($datei,"r+");
echo 'content: '.fread($dh, filesize($datei))."<BR>\n";
echo 'pointer after write at: '.ftell($dh).'<br>';
ftruncate($dh, '0');
echo 'pointer after truncate at: '.ftell($dh).'<br>';
echo 'filesize after truncate is: '.filesize($datei).'<br>';
fwrite($dh, $str2);
echo 'pointer after second write at: '.ftell($dh).'<br>';
rewind($dh);
echo 'pointer after rewind at: '.ftell($dh).'<br>';
echo 'content: '.fread($dh, filesize($datei)).'<br>';
clearstatcache();
echo 'content: '.fread($dh, filesize($datei));
fclose($dh);
?>

Expected result:
----------------
content: 1234
pointer after write at: 4
pointer after truncate at: 4
filesize after truncate is: 4
pointer after second write at: 6
pointer after rewind at: 0
content: 56
content: 56

Actual result:
--------------
content: 1234
pointer after write at: 4
pointer after truncate at: 4
filesize after truncate is: 4
pointer after second write at: 6
pointer after rewind at: 0
content: 
content: 56


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


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

Reply via email to