Repository navigation
Fix GH-24256: fclose() returns false for stream wrappers without stream_flush() - #25543
TiagoCruz1224 wants to merge 1 commit into
Conversation
|
I tested this against the current PHP-8.6 tip (1be37f6). The patch no longer applies cleanly there because Results on a CLI/FPM build with
The PR will need a rebase onto the current PHP-8.6 branch. I have not tested Windows.
|
…tream_flush() Since the fix for bug #60110, fclose(), file_put_contents() and copy() return the result of the flush on close. A user stream wrapper without stream_flush() made that flush fail, so these functions returned false although nothing went wrong. stream_flush() is optional, so when the stream is closed a missing one now means there was nothing to flush. An explicit fflush() still returns false for such a wrapper, and a stream_flush() that returns false still makes fclose() return false. Based on phpGH-24259 by lazerg.
4d97b1a to
01fc2ba
Compare
|
Thanks for testing this, @AceMedia. I rebased onto the current PHP-8.6 (d9567b9). The only conflict was with the NO_FCLOSE handling from GH-25586. The flag is still restored right after the I ran You're right about |
Since c07cc85 (bug #60110),
fclose(),file_put_contents()andcopy()return the result of the flush on close. A user wrapper withoutstream_flush()makes that flush fail, so these functions return false although all the data was written. Forfclose()this happens when something was written since the lastfflush(), because only then is there a flush on close.stream_flush()is optional, so when the stream is closed a missing one now counts as nothing to flush. An explicitfflush()still returns false for such a wrapper, and astream_flush()that returns false still makesfclose()return false.This picks up #24259 by @lazerg, which was closed for inactivity, with the same fix and a test that also covers the explicit
fflush()and a failingstream_flush().Fixes #24256
I prepared this change with AI assistance, then reviewed it and verified each case myself.