Bug->Doc #63473 [Opn->Asn]: rename rename
| From: | aharvey@php.net | Date: | Mon, 12 Nov 2012 01:56:36 +0000 |
| Subject: | Bug->Doc #63473 [Opn->Asn]: rename rename | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-9080@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63473&edit=1
ID: 63473
Updated by: aharvey@php.net
Reported by: anon at anon dot anon
Summary: rename rename
-Status: Open
+Status: Assigned
-Type: Bug
+Type: Documentation Problem
-Package: Filesystem function related
+Package: Documentation problem
PHP Version: 5.4.8
-Assigned To:
+Assigned To: aharvey
Block user comment: N
Private report: N
New Comment:
I'll update the manual to indicate that it overwrites the destination, but the behaviour of the
function is expected: it has the same semantics as the rename() C library function.
Previous Comments:
------------------------------------------------------------------------
[2012-11-09 18:39:01] anon at anon dot anon
Apparently PHP doesn't even have a way to merely rename a file. Using file_exists with rename
will be vulnerable to race conditions (potential file overwrites) with other processes.
------------------------------------------------------------------------
[2012-11-09 18:32:42] anon at anon dot anon
Description:
------------
The rename function overwrites. This is totally unexpected and unintuitive behavior which could
cause data loss, and it is not even documented.
Combined with the fact that the rename function can "rename" across drives, it's
obviously a move, not a rename. Then it should be called move, so you can tell what it does.
Test script:
---------------
<?php
file_put_contents('1.txt', 'one');
file_put_contents('2.txt', 'two');
rename('2.txt', '1.txt');
echo '1.txt:' . file_get_contents('1.txt');
echo '2.txt:' . file_get_contents('2.txt');
Expected result:
----------------
1.txt:one
2.txt:two
plus an error that the name exists
Actual result:
--------------
1.txt:two
2.txt:
plus an error that 2.txt does not exist
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63473&edit=1