Bug #68935 [Opn]: fwrite won't recreate deleted file or emit warning

From: Date: Wed, 28 Jan 2015 15:29:56 +0000
Subject: Bug #68935 [Opn]: fwrite won't recreate deleted file or emit warning
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190271@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68935&edit=1 ID: 68935 User updated by: mattsch at gmail dot com Reported by: mattsch at gmail dot com -Summary: fwrite won't recreate deleted file to write to +Summary: fwrite won't recreate deleted file or emit warning Status: Open Type: Bug Package: Filesystem function related Operating System: Gentoo Linux 13.0 PHP Version: 5.6.5 Block user comment: N Private report: N New Comment: Changed the summary to include the other potential expected result. Previous Comments: ------------------------------------------------------------------------ [2015-01-28 15:27:48] mattsch at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=68935&edit=1

« previous php.bugs (#190271) next »