From e47cf056a0a1b2bc805cac1a9a3544d47bdc33d2 Mon Sep 17 00:00:00 2001 From: Hani Rouatbi Date: Sat, 6 Dec 2025 15:51:41 +0100 Subject: [PATCH] Add PHP 8.5 support Updated calls to resource cleanup functions (curl_close, imagedestroy, finfo_close) to only execute for PHP versions below 8.0, as these functions have no effect in PHP 8+. Improved error handling and connection management in mysqli and sqlite drivers, and added missing DOCTYPE in error output for better HTML compliance. --- includes/FetchFile.php | 14 ++++++++++++-- includes/captcha.php | 7 ++++++- includes/common.php | 9 ++++++++- includes/functions_display.php | 1 + includes/mysqli.php | 23 ++++++++++++++++++----- includes/sqlite.php | 12 ++++++++---- includes/up_helpers/others.php | 7 ++++++- includes/up_helpers/thumbs.php | 9 +++++++-- 8 files changed, 66 insertions(+), 16 deletions(-) diff --git a/includes/FetchFile.php b/includes/FetchFile.php index 403f2ce..e247114 100644 --- a/includes/FetchFile.php +++ b/includes/FetchFile.php @@ -131,7 +131,12 @@ class FetchFile kleeja_log(sprintf("cUrl error (#%d): %s\n", curl_errno($ch), htmlspecialchars(curl_error($ch)))); } - curl_close($ch); + // curl_close() has no effect since PHP 8.0 + // Only call it for PHP < 8.0 where it actually closes the handle + if (PHP_VERSION_ID < 80000) + { + curl_close($ch); + } fclose($out); return isset($error) ? false : true; @@ -146,7 +151,12 @@ class FetchFile kleeja_log(sprintf("FetchFile error (curl: #%d): %s\n", curl_errno($ch), htmlspecialchars(curl_error($ch)))); } - curl_close($ch); + // curl_close() has no effect since PHP 8.0 + // Only call it for PHP < 8.0 where it actually closes the handle + if (PHP_VERSION_ID < 80000) + { + curl_close($ch); + } return isset($error) ? false : $data; } diff --git a/includes/captcha.php b/includes/captcha.php index b982722..83aa204 100755 --- a/includes/captcha.php +++ b/includes/captcha.php @@ -101,7 +101,12 @@ function kleeja_cpatcha_image() imagepng($image); //Free up resources - imagedestroy($image); + // imagedestroy() has no effect since PHP 8.0 + // Only call it for PHP < 8.0 where it actually frees memory + if (PHP_VERSION_ID < 80000) + { + imagedestroy($image); + } } //<--- EOF diff --git a/includes/common.php b/includes/common.php index 23ea251..3010446 100755 --- a/includes/common.php +++ b/includes/common.php @@ -66,9 +66,15 @@ error_reporting(defined('DEV_STAGE') ? E_ALL : E_ALL ^ E_NOTICE); */ function kleeja_show_error($error_number, $error_string = '', $error_file = '', $error_line = '') { + // Check if error reporting is disabled (happens with @ operator) + if (!(error_reporting() & $error_number)) + { + return false; + } + switch ($error_number) { - case E_NOTICE: case E_WARNING: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: + case E_NOTICE: case E_WARNING: case E_USER_WARNING: case E_USER_NOTICE: case 2048: // E_STRICT (deprecated in PHP 8.4, using numeric value for compatibility) if (function_exists('kleeja_log')) { $error_name = [ @@ -81,6 +87,7 @@ function kleeja_show_error($error_number, $error_string = '', $error_file = '', default: header('HTTP/1.1 503 Service Temporarily Unavailable'); + echo '' . "\n"; echo '' . "\n\n"; echo '' . "\n"; echo 'Kleeja Error' . "\n" . '