|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53328 copy() returns false even if closing the destination file fails
Submitted: 2010-11-17 06:48 UTC Modified: 2011-08-30 12:41 UTC
From: mike at silverorange dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.3.3 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mike at silverorange dot com
New email:
PHP Version: OS:


 [2010-11-17 06:48 UTC] mike at silverorange dot com
In a custom stream wrapper if stream_flush() returns false as the documentation 
says it may, parent copy operations do not return false.

Test script:

Expected result:
copy should return false.

Actual result:
copy returns true.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-17 15:43 UTC]
Hey Mike,

I wanted to write a test case but I fail to reproduce this on 5.3.2 so far.

E.g., I wrapped your code into a phpt, all I get is:

Warning: copy(): The second argument to copy() function cannot be a directory in 
/home/till/test/bug53328.php on line 60

[ On a sidenote, I don't get this error message either. 'foo' is not a 
directory, but maybe this means that we have to implement more in the example 
wrapper for it to work, or this is another bug in the streamwrapper?]

Anyway, aside from the weird error message it seems to work indeed on 5.3.2.

Here is your code wrapped in a phpt:

Execute with: pear run-tests bug53328.phpt
 [2010-11-17 16:36 UTC] mike at silverorange dot com
-PHP Version: 5.2.14 +PHP Version: 5.3.3
 [2010-11-17 16:36 UTC] mike at silverorange dot com
Till, thanks for making the phpt file. I tested using the phpt and the raw PHP 
file, and both fail as described in the original bug report. This is using php 
5.3.3 as provided by Ubuntu.

I don't see the directory error you describe.
 [2010-11-18 07:52 UTC]
-Summary: stream_flush error does not cause copy to return false +Summary: copy() returns false even if closing the destination file fails
 [2010-11-18 07:52 UTC]
The function you should be testing would be fflush, not copy. fflush does actually return false.

The flush operation is called for collaterals when closing the file. copy() should probably return false if closing, at least, the destination file fails, but it's a risky move because in PHP, for better or worse, the return value of php_stream_close and friends is almost always ignored. We'd be giving significance to something that's almost always ignored.

Maybe for trunk...
 [2010-11-18 17:37 UTC] mike at silverorange dot com
fflush does correctly return false, but the point of stream wrappers is to be 
able to use the stream functions as I normally would. I normally use copy to 
copy a stream rather than an fopen, fread, fwrite, fflush, fclose loop.

Because of this bug, there's no way to properly detect errors when copying to 
custom streams. In practice, this results in data loss.

I'm fine with the fix going in trunk as afaik php 5.2.x is reaching end of life 
and this is not a security issue.
 [2011-08-30 12:41 UTC]
-Status: Open +Status: Bogus
 [2011-08-30 12:41 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

The php-src internal copy() function discards the flush operation, even using its 
native wrappers.

If you consider it an issue, you should enforce flushing in your wrapper 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 08:01:32 2024 UTC