|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-01-28 15:27 UTC] 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)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 14:00:01 2025 UTC |
> BTW, is it possible to rename opened files under windows? No: $f = fopen('foo', 'w'); rename('foo', 'bar'); Warning: rename(foo,bar): Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird. [The process can't access the file, because it's used by another process.] It seems to me that several file operations work quite differently on *nix and Windows, and that these differences deserve better documentation in the PHP manual.