From:             rc at opelgt dot org
Operating system: MacOSX 10.3
PHP version:      4.3.4
PHP Bug Type:     Filesystem function related
Bug description:  Different behaviour of fopen depending on r+,w+,a+

Description:
------------
Hello,

for my skill its a bit too much to understand whats 
going on here.

Reproduce code:
---------------
<?php
$alt = '1234567890';
$neu = '13579';

$datei = 'test.txt';
$dh = fopen ($datei,"w");
fwrite($dh, $alt);
fclose($dh);
// pos1
$dh = fopen ($datei,"a+"); // just alter the mode to test others
rewind($dh);
echo "Inhalt<BR>\nalt: ".fread($dh, filesize($datei))."<BR>\n";
ftruncate($dh, '0');
fwrite($dh, $neu);
rewind($dh);
echo 'neu: '.fread($dh, filesize($datei));
fclose($dh);
?>

Expected result:
----------------
I wrote the code above and exspected same behaviour for 
r+, w+ and a+.

Before pos1 The content of 'test.txt' is written to 
'1234567890'.
After pos1 the file is opened anothertime with r+,w+ or 
a+.
Rewind sets the pointer to '0'.
So that fread can read the file from the beginning. 
Ftruncate makes the size of the file to '0' and sets the 
pointer to the beginning of the file.
Fwrite writes the new content and the size of the file 
will be as big as nessessary for the content.
Rewind takes the pointer back from end to beginning of 
the file.

Actual result:
--------------
Echo should tell the new content.
This only works with a+, but with r+ and w+ nothing is 
displayed.

The first echo command tells the 'old' content in a+ and 
r+ mode, but not with w+.

Seems to me there are undocumented differences between 
the modes that makes it difficult to choose and use one 
of them.

R�diger

-- 
Edit bug report at http://bugs.php.net/?id=28371&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28371&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28371&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28371&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28371&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28371&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28371&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28371&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28371&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28371&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28371&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28371&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28371&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28371&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28371&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28371&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28371&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28371&r=float

Reply via email to