php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #63473 rename rename
Submitted: 2012-11-09 18:32 UTC Modified: 2012-11-12 02:00 UTC
From: anon at anon dot anon Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.4.8 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: anon at anon dot anon
New email:
PHP Version: OS:

 

 [2012-11-09 18:32 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-09 18:39 UTC] 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-12 01:56 UTC] aharvey@php.net
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.
 [2012-11-12 01:56 UTC] aharvey@php.net
-Status: Open +Status: Assigned -Type: Bug +Type: Documentation Problem -Package: Filesystem function related +Package: Documentation problem -Assigned To: +Assigned To: aharvey
 [2012-11-12 02:00 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=328311
Log: Update the rename() description to note that it overwrites and moves between
directories.

Fixes doc bug #63473 (rename rename).
 [2012-11-12 02:00 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2012-11-12 02:00 UTC] aharvey@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2012-11-13 06:56 UTC] anon at anon dot anon
Alright, thanks.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Fri Mar 20 23:00:02 2026 UTC