|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29257 breaking copy file to the same
Submitted: 2004-07-19 15:06 UTC Modified: 2004-08-01 01:00 UTC
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: zet at male dot ru Assigned:
Status: No Feedback Package: *Directory/Filesystem functions
PHP Version: 4.3.7 OS: Windows XP SP1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
41 + 30 = ?
Subscribe to this entry?

 [2004-07-19 15:06 UTC] zet at male dot ru
When i copy file with function copy, like this
copy("C:\file.gif", "C:\file.gif"), file was break. His size is 0. 

Reproduce code:
copy("C:\file.gif", "C:\file.gif");

Expected result:
IMHO file must stand without changes.

Actual result:
File changed. His size is 0.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-20 02:47 UTC]
what happens if you do: 
copy("C:\\file.gif", "C:\\file.gif") 
 [2004-08-01 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-01-14 21:40 UTC] chernyshevsky at hotmail dot com
How come no one is looking into this? It's reproducible on Linux as well. 

copy("test.txt", "test.txt") -> 0 bytes

You can't avoid this problem just by checking the filename, since one could be a symlink pointing to the other. It would introduce platform dependency as well (case-insensitivity on Windows).
 [2005-02-11 07:04 UTC] nasheet at hotmail dot com
Reproducible with Windows and Linux, looks like platform independant:


Actual result:
File changed to 0 bytes.
 [2005-07-29 04:45 UTC] richard dot managh at gmail dot com
Same behaviour here, on winxp with php4 and debian with php5, seems conceptually wrong, I would report the exact versions but it would seem this behaviour is constant on every version. Where is the sanity in truncating a file to 0 bytes if the code attempts to copy it over itself? Should preferably check for equivalent filepaths and not perform the copy function, or at least report a warning that the files were the same, both command line copy and cp (win and linux) do that.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Oct 20 20:03:33 2021 UTC