Skip to content

Guard fclose() against false stream in supercache-only mode#1053

Merged
donnchawp merged 2 commits into
trunkfrom
fix/1016-fclose-false-guard
May 27, 2026
Merged

Guard fclose() against false stream in supercache-only mode#1053
donnchawp merged 2 commits into
trunkfrom
fix/1016-fclose-false-guard

Conversation

@donnchawp
Copy link
Copy Markdown
Contributor

Fixes #1016.

In supercache-only mode $fr is false (the wp-cache file is never opened). When the supercache temp file fails to open, the error branches in wp_cache_get_ob() called @fclose( $fr ) — i.e. @fclose( false ). On PHP 8+ that is a TypeError, which @ does not suppress, so the request fatals (matches the report's fclose(): Argument #1 ($stream) must be of type resource, false given).

Fix: only call fclose() when the stream is actually open. Two call sites guarded; the adjacent fclose( $fr2 ) is left as-is because $fr2 is a valid resource on that branch.

Note: PR #1042 also contains this fix (bundled with the #1019 $blog_id cast and two redundant guards). This PR isolates just the #1016 fix.

In supercache-only mode $fr is false (the wp-cache file is never opened). When the supercache temp file fails to open, the error branches called @fclose( $fr ) = @fclose( false ). On PHP 8+ that is a TypeError, which @ does not suppress, so the request fatals. Only call fclose() when the stream is open.

Fixes #1016.
phpcs-changed flags the now-modified fclose() lines under WordPress.WP.AlternativeFunctions; match the file's existing inline-ignore convention for direct filesystem calls.
@donnchawp donnchawp merged commit a38c852 into trunk May 27, 2026
6 checks passed
@donnchawp donnchawp mentioned this pull request May 27, 2026
@donnchawp donnchawp deleted the fix/1016-fclose-false-guard branch May 27, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WP Super Cache fclose(): Argument #1 ($stream) must be of type resource, false given

1 participant