Fix Type Casting Issue in Jetpack Boost functions-helpers.php
-
Hello Support Team,
I am experiencing an issue with the Jetpack Boost plugin related to the file functions-helpers.php located in the
/app/lib/minify/
directory. The error log displays the following message:[18-Feb-2025 03:40:26 UTC] PHP Fatal error: Uncaught TypeError: Unsupported operand types: int - string in /home/***/public_html/wp-content/plugins/jetpack-boost/app/lib/minify/functions-helpers.php:76 Stack trace: #0 /home/***/public_html/wp-content/plugins/jetpack-boost/app/lib/minify/functions-helpers.php(32): jetpack_boost_delete_expired_files(Array, '/home/mfkvhsiie...') #1 /home/***/public_html/wp-includes/class-wp-hook.php(324): jetpack_boost_legacy_minify_cache_cleanup('/home/mfkvhsiie...') #2 /home/***/public_html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array) #3 /home/***/public_html/wp-includes/plugin.php(565): WP_Hook->do_action(Array) #4 /home/***/public_html/wp-cron.php(191): do_action_ref_array('jetpack_boost_m...', Array) #5 {main} thrown in /home/***/public_html/wp-content/plugins/jetpack-boost/app/lib/minify/functions-helpers.php on line 76
It appears that the error occurs because there is an attempt to subtract a string from an integer. The original code is as follows:
if ( ( time() - $file_age ) > fileatime( $file ) ) { wp_delete_file( $file ); } elseif ( ( time() - ( 2 * $file_age ) ) > filemtime( $file ) ) { wp_delete_file( $file ); }
The problem arises because the variable
$file_age
is not explicitly cast as a numeric value before the arithmetic operation, leading to a type error when its value is not purely numeric.The proposed fix is to cast
$file_age
to an integer, ensuring that arithmetic operations are performed on valid numeric values. The corrected code is:if ( ( time() - (int) $file_age ) > (int) fileatime( $file ) ) { wp_delete_file( $file ); } elseif ( ( time() - ( 2 * (int) $file_age ) ) > (int) filemtime( $file ) ) { wp_delete_file( $file ); }
I kindly request that you review this change and update the plugin accordingly in the next release to permanently resolve the issue.
Thank you for your attention and support.
Best regards.
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.