From 047a447585932dfe41cf1a1bbe0886a7b1165652 Mon Sep 17 00:00:00 2001 From: Linty Date: Tue, 17 Dec 2024 12:16:11 +0100 Subject: [PATCH] issue #2294 compatibility with PHP 8.4+ for session handling PHP7+ to PHP 9 compatibility --- include/functions_session.inc.php | 44 +++++++++++++++++++++++++------ install.php | 9 ++----- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/include/functions_session.inc.php b/include/functions_session.inc.php index 747fabfc8..6093abca8 100644 --- a/include/functions_session.inc.php +++ b/include/functions_session.inc.php @@ -10,19 +10,47 @@ * @package functions\session */ + // see https://php.watch/versions/8.4/session_set_save_handler-alt-signature-deprecated + class PwgSession implements SessionHandlerInterface { + public function open(string $path, string $name): bool + { + return pwg_session_open($path, $name); + } + + public function close(): bool + { + return pwg_session_close(); + } + + public function read(string $id): string + { + return pwg_session_read($id); + } + + public function write(string $id, string $data): bool + { + return pwg_session_write($id, $data); + } + + public function destroy(string $id): bool + { + return pwg_session_destroy($id); + } + + public function gc(int $max_lifetime): int + { + return pwg_session_gc(); + } +} if (isset($conf['session_save_handler']) and ($conf['session_save_handler'] == 'db') and defined('PHPWG_INSTALLED')) { - session_set_save_handler( - 'pwg_session_open', - 'pwg_session_close', - 'pwg_session_read', - 'pwg_session_write', - 'pwg_session_destroy', - 'pwg_session_gc' - ); + // In PHP 8.4+ calling session_set_save_handler with + // two parameters is deprecated. To correct this, + // we pass a SessionHandlerInterface instance. + session_set_save_handler(new PwgSession()); if (function_exists('ini_set')) { diff --git a/install.php b/install.php index 31c92d772..9ec235025 100644 --- a/install.php +++ b/install.php @@ -466,13 +466,8 @@ else } else { - session_set_save_handler('pwg_session_open', - 'pwg_session_close', - 'pwg_session_read', - 'pwg_session_write', - 'pwg_session_destroy', - 'pwg_session_gc' - ); + // See include/functions_session.inc.php + session_set_save_handler(new PwgSession()); if ( function_exists('ini_set') ) { ini_set('session.use_cookies', $conf['session_use_cookies']);