From 1c075db759d0bdcddb9eb78eba7cef1b7e6f135d Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh <5656673+donnchawp@users.noreply.github.com> Date: Wed, 27 May 2026 18:15:09 +0100 Subject: [PATCH 1/2] Guard fclose() against false stream in supercache-only mode 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. --- wp-cache-phase2.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index c1369415..ea282471 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -2418,7 +2418,9 @@ function wp_cache_get_ob( &$buffer ) { if ( ! $fr2 ) { wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ), 1 ); wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) ); - @fclose( $fr ); + if ( $fr ) { + fclose( $fr ); + } @unlink( $tmp_wpcache_filename ); wp_cache_writers_exit(); return wp_cache_maybe_dynamic( $buffer ); @@ -2430,7 +2432,9 @@ function wp_cache_get_ob( &$buffer ) { if ( ! $gz ) { wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ) . '.gz', 1 ); wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . '.gz' ); - @fclose( $fr ); + if ( $fr ) { + fclose( $fr ); + } @unlink( $tmp_wpcache_filename ); @fclose( $fr2 ); @unlink( $tmp_cache_filename ); From 2251f01b930cec91d5af4ee5ae128736bf0ea58e Mon Sep 17 00:00:00 2001 From: Donncha O Caoimh <5656673+donnchawp@users.noreply.github.com> Date: Wed, 27 May 2026 18:21:19 +0100 Subject: [PATCH 2/2] Silence AlternativeFunctions warning on guarded fclose calls phpcs-changed flags the now-modified fclose() lines under WordPress.WP.AlternativeFunctions; match the file's existing inline-ignore convention for direct filesystem calls. --- wp-cache-phase2.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index ea282471..8a1632c7 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -2419,7 +2419,7 @@ function wp_cache_get_ob( &$buffer ) { wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ), 1 ); wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) ); if ( $fr ) { - fclose( $fr ); + fclose( $fr ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose } @unlink( $tmp_wpcache_filename ); wp_cache_writers_exit(); @@ -2433,7 +2433,7 @@ function wp_cache_get_ob( &$buffer ) { wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ) . '.gz', 1 ); wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . '.gz' ); if ( $fr ) { - fclose( $fr ); + fclose( $fr ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose } @unlink( $tmp_wpcache_filename ); @fclose( $fr2 );