Bug #68935 [NEW]: fwrite won't recreate deleted file to write to
| From: | mattsch at gmail dot com | Date: | Wed, 28 Jan 2015 15:27:49 +0000 |
| Subject: | Bug #68935 [NEW]: fwrite won't recreate deleted file to write to | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-190270@lists.php.net to get a copy of this message | ||
From: mattsch at gmail dot com
Operating system: Gentoo Linux 13.0
PHP version: 5.6.5
Package: Filesystem function related
Bug Type: Bug
Bug description:fwrite won't recreate deleted file to write to
Description:
------------
Open/create a file with fopen. Then delete the file with unlink.
Finally, write to that already opened resource with fwrite. fwrite
reports the number of bytes written without any errors but the file no
longer exists so nothing is actually written to a file. One of two
options should happen:
1. fwrite should emit a warning and report bytes written as false
or
2. fwrite should recreate the deleted file and write to it and report
the bytes written.
Test script:
---------------
<?php
$resource = fopen('foo', 'w');
unlink('foo');
$bytesWritten = @fwrite($file, 'bar');
$error = error_get_last();
var_dump($error);
var_dump($bytesWritten);
var_dump(file_exists('foo'));
Expected result:
----------------
array(4) {
["type"]=>
int(2)
["message"]=>
string(58) "fwrite(): cannot write to file because file no longer
exists"
["file"]=>
string(27) "/home/foo/foo.php"
["line"]=>
int(4)
}
bool(false)
bool(false)
--or--
NULL
int(3)
bool(true)
Actual result:
--------------
NULL
int(3)
bool(false)
--
Edit bug report at https://bugs.php.net/bug.php?id=68935&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68935&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68935&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68935&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68935&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68935&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68935&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68935&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68935&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68935&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68935&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68935&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68935&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68935&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68935&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68935&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68935&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68935&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68935&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68935&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68935&r=mysqlcfg