From 5d3ab97192f91b62cbb8fe904aa0391b1485ff28 Mon Sep 17 00:00:00 2001 From: erwin Date: Wed, 3 Dec 2025 19:32:28 +0100 Subject: [PATCH] Fix PHP 8.4 session handler compatibility and add return type hints --- framework/web/CHttpSession.php | 53 +++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/framework/web/CHttpSession.php b/framework/web/CHttpSession.php index 0004f3a32..8675bafc0 100644 --- a/framework/web/CHttpSession.php +++ b/framework/web/CHttpSession.php @@ -117,7 +117,7 @@ class CHttpSession extends CApplicationComponent implements IteratorAggregate,Ar if ($this->getUseCustomStorage()) { // PHP 8.4+ deprecates callback-style session_set_save_handler(). // Use object-style handler on PHP 8.0+ to avoid deprecation. - if (PHP_VERSION_ID >= 80000) { + if (PHP_VERSION_ID >= 70000) { session_set_save_handler(new CHttpSessionHandler($this), true); } else { @session_set_save_handler( @@ -679,39 +679,76 @@ class CHttpSession extends CApplicationComponent implements IteratorAggregate,Ar */ class CHttpSessionHandler implements SessionHandlerInterface { - private CHttpSession $_session; + /** + * @var CHttpSession + */ + private $_session; + /** + * @param CHttpSession $session + */ public function __construct(CHttpSession $session) { $this->_session = $session; } - public function open(string $path, string $name): bool + /** + * @param string $path + * @param string $name + * @return bool + */ + #[ReturnTypeWillChange] + public function open($path, $name) { return $this->_session->openSession($path, $name); } - public function close(): bool + /** + * @return bool + */ + #[ReturnTypeWillChange] + public function close() { return $this->_session->closeSession(); } - public function read(string $id): string|false + /** + * @param string $id + * @return string|false + */ + #[ReturnTypeWillChange] + public function read($id) { return $this->_session->readSession($id); } - public function write(string $id, string $data): bool + /** + * @param string $id + * @param string $data + * @return bool + */ + #[ReturnTypeWillChange] + public function write($id, $data) { return $this->_session->writeSession($id, $data); } - public function destroy(string $id): bool + /** + * @param string $id + * @return bool + */ + #[ReturnTypeWillChange] + public function destroy($id) { return $this->_session->destroySession($id); } - public function gc(int $max_lifetime): int|false + /** + * @param int $max_lifetime + * @return int|false + */ + #[ReturnTypeWillChange] + public function gc($max_lifetime) { return $this->_session->gcSession($max_lifetime) ? 0 : false; }