Skip to content

PHP 8.4 depreciations : non-working fix for session_set_save_handler() #2150

@er314

Description

@er314

Regarding issue :
#2071 (comment)

Deprecated: session_set_save_handler(): Providing individual callbacks instead of an object implementing SessionHandlerInterface is deprecated in /var/www/html/wire/core/WireSessionHandler.php on line 51

it recently received a fix, with this code added to WireSessionHandler.php :

 	if(version_compare(PHP_VERSION, '8.4.0') >= 0) {
 			session_set_save_handler($this);
 	}

However, this code still doesn't "compile", because the signature for session_set_save_handler() is expecting an object of class implementing \SessionHandlerInterface, which $this is not.

-> FYI, I got it to "compile" (not really tested, but there's no more error and the web site seems to work well),
with no code refactoring,
by replacing :

			session_set_save_handler($this);

with :

			$sessionHandler = new class($this) implements \SessionHandlerInterface {
				private WireSessionHandler $wireSessionHandler;
				public function __construct(WireSessionHandler $wireSessionHandler) { $this->wireSessionHandler = $wireSessionHandler; }
				public function open($path, $name) { return $this->wireSessionHandler->open($path, $name); }
				public function close() { return $this->wireSessionHandler->close(); }
				public function read($id) { return $this->wireSessionHandler->read($id); }
				public function write($id, $data) { return $this->wireSessionHandler->write($id, $data); }
				public function destroy($id) { return $this->wireSessionHandler->destroy($id); }
				public function gc($seconds) { return $this->wireSessionHandler->gc($seconds); }
			};
			session_set_save_handler($sessionHandler);

note : based off porting guidelines described here : https://php.watch/versions/8.4/session_set_save_handler-alt-signature-deprecated

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions