note 104104 deleted from function.session-set-save-handler by cmb
| From: | cmb@php.net | Date: | Sun, 24 Nov 2019 09:12:53 +0000 |
| Subject: | note 104104 deleted from function.session-set-save-handler by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-213243@lists.php.net to get a copy of this message | ||
Note Submitter: lukas.starecek
----
I have solved problem with session handler, which needs some other objects (for example DB access
object), with register_shutdown_function. Just calling
<?php
register_shutdown_function('session_write_close');
?>
solved my problem. Shutdown functions are called before object destructors.
If you use class for session handling (my prefered way), you can call register_shutdown_function in
constructor and you must not mess your code in another place.
Example:
<?php
class SessionHandler {
protected $_db;
public function __construct(PDO $db) {
$this->_db = $db;
register_shutdown_function('session_write_close');
}
function open($save_path, $session_name) {
}
function close() {
}
function read($id) {
}
function write($id, $sess_data) {
}
function destroy($id) {
}
function gc($maxlifetime) {
}
}
?>