Skip to content

Commit 81226a7

Browse files
committed
Make session_set_save_handler call compatible with 8.4
1 parent d7519ba commit 81226a7

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

Diff for: core/model/modx/modsessionhandler.class.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @package modx
1515
*/
16-
class modSessionHandler {
16+
class modSessionHandler implements SessionHandlerInterface {
1717
/**
1818
* @var modX A reference to the modX instance controlling this session
1919
* handler.
@@ -60,11 +60,14 @@ function __construct(modX &$modx) {
6060
/**
6161
* Opens the connection for the session handler.
6262
*
63+
* @param $path
64+
* @param $name
6365
* @access public
6466
* @return boolean Always returns true; actual connection is managed by
6567
* {@link modX}.
6668
*/
67-
public function open() {
69+
#[\ReturnTypeWillChange]
70+
public function open($path, $name) {
6871
return true;
6972
}
7073

@@ -75,6 +78,7 @@ public function open() {
7578
* @return boolean Always returns true; actual connection is managed by
7679
* {@link modX}
7780
*/
81+
#[\ReturnTypeWillChange]
7882
public function close() {
7983
return true;
8084
}
@@ -86,6 +90,7 @@ public function close() {
8690
* @param integer $id The pk of the {@link modSession} object.
8791
* @return string The data read from the {@link modSession} object.
8892
*/
93+
#[\ReturnTypeWillChange]
8994
public function read($id) {
9095
if ($this->_getSession($id)) {
9196
$data= $this->session->get('data');
@@ -103,6 +108,7 @@ public function read($id) {
103108
* @param mixed $data The data to write to the session.
104109
* @return boolean True if successfully written.
105110
*/
111+
#[\ReturnTypeWillChange]
106112
public function write($id, $data) {
107113
$written= false;
108114
if ($this->_getSession($id, true)) {
@@ -122,6 +128,7 @@ public function write($id, $data) {
122128
* @param integer $id
123129
* @return boolean True if the session record was destroyed.
124130
*/
131+
#[\ReturnTypeWillChange]
125132
public function destroy($id) {
126133
if ($this->_getSession($id)) {
127134
$destroyed= $this->session->remove();
@@ -139,6 +146,7 @@ public function destroy($id) {
139146
* longer than.
140147
* @return boolean True if session records were removed.
141148
*/
149+
#[\ReturnTypeWillChange]
142150
public function gc($max) {
143151
$maxtime= time() - $this->gcMaxLifetime;
144152
return $this->modx->removeCollection('modSession', array("{$this->modx->escape('access')} < {$maxtime}"));

Diff for: core/model/modx/modx.class.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -2564,14 +2564,18 @@ protected function _initSession($options = null) {
25642564
if ($sessionHandlerClass = $this->getOption('session_handler_class', $options)) {
25652565
if ($shClass = $this->loadClass($sessionHandlerClass, '', false, true)) {
25662566
if ($sh = new $shClass($this)) {
2567-
session_set_save_handler(
2568-
array (& $sh, 'open'),
2569-
array (& $sh, 'close'),
2570-
array (& $sh, 'read'),
2571-
array (& $sh, 'write'),
2572-
array (& $sh, 'destroy'),
2573-
array (& $sh, 'gc')
2574-
);
2567+
if ($sh instanceof SessionHandlerInterface) {
2568+
session_set_save_handler($sh);
2569+
} elseif (version_compare(phpversion(), '8.4.0', '<')) {
2570+
session_set_save_handler(
2571+
[& $sh, 'open'],
2572+
[& $sh, 'close'],
2573+
[& $sh, 'read'],
2574+
[& $sh, 'write'],
2575+
[& $sh, 'destroy'],
2576+
[& $sh, 'gc']
2577+
);
2578+
}
25752579
}
25762580
}
25772581
}

0 commit comments

Comments
 (0)