Bug #80088 [NEW]: c+ open mode messes up file on fwrite()
| From: | smitty7523 at yahoo dot com | Date: | Thu, 10 Sep 2020 22:19:21 +0000 |
| Subject: | Bug #80088 [NEW]: c+ open mode messes up file on fwrite() | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-228965@lists.php.net to get a copy of this message | ||
From: smitty7523 at yahoo dot com
Operating system: Linux Manjaro
PHP version: 7.4.10
Package: Filesystem function related
Bug Type: Bug
Bug description:c+ open mode messes up file on fwrite()
Description:
------------
I am trying to insert a line in a file after a line that is searched
for.
The line to insert is inserted fine, but the text after it gets
truncated partially.
********* test.txt ************
PHP is a great language.
It is a tool for the ages.
It is easy to use and fast too!
Test script:
---------------
$absoluteFilePath = '<your_root_path>/test.txt';
$splFile = new \SplFileObject($absoluteFilePath, 'c+');
$splFile->flock(LOCK_EX);
$splFile->rewind();
// Add to next line.
while ($splFile->valid()) {
$currentLine = $splFile->fgets();
if (strpos($currentLine, "It is a tool for the ages.") !== false) {
$splFile->fwrite("But it has a few bugs.\n");
}
}
$splFile->flock(LOCK_UN);
Expected result:
----------------
PHP is a great language.
It is a tool for the ages.
But it has a few bugs.
It is easy to use and fast too!
Actual result:
--------------
PHP is a great language.
It is a tool for the ages.
But it has a few bugs.
ast too!
--
Edit bug report at https://bugs.php.net/bug.php?id=80088&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80088&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80088&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80088&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80088&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80088&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80088&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80088&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80088&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80088&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80088&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80088&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80088&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80088&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80088&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80088&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80088&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80088&r=mysqlcfg