note 129229 added to function.session-set-save-handler

From: Date: Fri, 09 Feb 2024 07:23:36 +0000
Subject: note 129229 added to function.session-set-save-handler
Groups: php.notes 
Request: Send a blank email to php-notes+get-221183@lists.php.net to get a copy of this message
if you use the interface (SessionHandlerInterface) to implement the storage of the session in the mysql database, it is not clear what the read method should return, because the return is specified in the interface: string|false, that is, if I refer to the type: public function read(string $id): string|false { if ($id) { $sql = "SELECT session_id, data FROM session WHERE session_id = '" . $this->db->escape($id) . "'"; pp($sql); $query = $this->db->query($sql); if ($query->num_rows) { //return (isset($query->one['data']) ? (array)json_decode($query->one['data'], true) : []); return $query->one['session_id']; } else { return ''; } } return false; } ref.: https://www.php.net/manual/ru/sessionhandlerinterface.read.php then I will receive an error response of the following plan: Error #: 2, message: session_start(): Failed to decode session object. Session has been destroyed ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.131 (proxied: 31.43.49.8) ---- Manual Page -- https://php.net/manual/en/function.session-set-save-handler.php Edit -- https://main.php.net/note/edit/129229 Del: integrated -- https://main.php.net/note/delete/129229/integrated Del: useless -- https://main.php.net/note/delete/129229/useless Del: bad code -- https://main.php.net/note/delete/129229/bad+code Del: spam -- https://main.php.net/note/delete/129229/spam Del: non-english -- https://main.php.net/note/delete/129229/non-english Del: in docs -- https://main.php.net/note/delete/129229/in+docs Del: other reasons-- https://main.php.net/note/delete/129229 Reject -- https://main.php.net/note/reject/129229 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221183) next »