diff --git a/core/model/modx/modsessionhandler.class.php b/core/model/modx/modsessionhandler.class.php index a9ae6b9b71..1efd564d00 100644 --- a/core/model/modx/modsessionhandler.class.php +++ b/core/model/modx/modsessionhandler.class.php @@ -13,7 +13,7 @@ * * @package modx */ -class modSessionHandler { +class modSessionHandler implements SessionHandlerInterface { /** * @var modX A reference to the modX instance controlling this session * handler. @@ -60,11 +60,14 @@ function __construct(modX &$modx) { /** * Opens the connection for the session handler. * + * @param $path + * @param $name * @access public * @return boolean Always returns true; actual connection is managed by * {@link modX}. */ - public function open() { + #[\ReturnTypeWillChange] + public function open($path, $name) { return true; } @@ -75,6 +78,7 @@ public function open() { * @return boolean Always returns true; actual connection is managed by * {@link modX} */ + #[\ReturnTypeWillChange] public function close() { return true; } @@ -86,6 +90,7 @@ public function close() { * @param integer $id The pk of the {@link modSession} object. * @return string The data read from the {@link modSession} object. */ + #[\ReturnTypeWillChange] public function read($id) { if ($this->_getSession($id)) { $data= $this->session->get('data'); @@ -103,6 +108,7 @@ public function read($id) { * @param mixed $data The data to write to the session. * @return boolean True if successfully written. */ + #[\ReturnTypeWillChange] public function write($id, $data) { $written= false; if ($this->_getSession($id, true)) { @@ -122,6 +128,7 @@ public function write($id, $data) { * @param integer $id * @return boolean True if the session record was destroyed. */ + #[\ReturnTypeWillChange] public function destroy($id) { if ($this->_getSession($id)) { $destroyed= $this->session->remove(); @@ -139,6 +146,7 @@ public function destroy($id) { * longer than. * @return boolean True if session records were removed. */ + #[\ReturnTypeWillChange] public function gc($max) { $maxtime= time() - $this->gcMaxLifetime; return $this->modx->removeCollection('modSession', array("{$this->modx->escape('access')} < {$maxtime}")); diff --git a/core/model/modx/modx.class.php b/core/model/modx/modx.class.php index fa05d4ee18..8f4f415f8d 100644 --- a/core/model/modx/modx.class.php +++ b/core/model/modx/modx.class.php @@ -2564,14 +2564,18 @@ protected function _initSession($options = null) { if ($sessionHandlerClass = $this->getOption('session_handler_class', $options)) { if ($shClass = $this->loadClass($sessionHandlerClass, '', false, true)) { if ($sh = new $shClass($this)) { - session_set_save_handler( - array (& $sh, 'open'), - array (& $sh, 'close'), - array (& $sh, 'read'), - array (& $sh, 'write'), - array (& $sh, 'destroy'), - array (& $sh, 'gc') - ); + if ($sh instanceof SessionHandlerInterface) { + session_set_save_handler($sh); + } elseif (version_compare(phpversion(), '8.4.0', '<')) { + session_set_save_handler( + [& $sh, 'open'], + [& $sh, 'close'], + [& $sh, 'read'], + [& $sh, 'write'], + [& $sh, 'destroy'], + [& $sh, 'gc'] + ); + } } } }