|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-05-26 02:37 UTC] wangyuan at lianlife dot com
Description:
------------
I can't catch the exception that is thrown from the write method in the sess class, but other methods can work properly, such as open (), read () and other.
I'm not sure PHP itself is designed, or is it a bug.
Run result in the console :
Test script:
---------------
class sess extends SessionHandler {
public function read($session_id) {
throw new Exception('read');
}
public function write($session_id, $session_data) {
throw new Exception('write');
}
}
try {
$handler = new sess();
session_set_save_handler($handler, true);
session_start();
$_SESSION['name'] = 'php';
$_SESSION['gender'] = 'female';
echo $_SESSION['name'];
} catch (Exception $e) {
echo '<pre>';
print_r($e);
echo '</pre>';
}
Expected result:
----------------
The following information should be catch, but it is displayed as "excetpion Uncaught"
2016/05/26 10:17:37 [error] 13474#0: *19551 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught exception 'Exception' with message '0jib891huoct6e4lpl5i3f9tt7name|s:8:"wangyuan";gender|s:4:"male";' in /data/web/ndl/test.php:11
Stack trace:
#0 [internal function]: sess->write('0jib891huoct6e4...', 'name|s:8:"wangy...')
#1 [internal function]: session_write_close()
#2 {main}
thrown in /data/web/ndl/test.php on line 11" while reading response header from upstream, client: 10.24.18.243, server: ndl.lianlife.com, request: "GET /test.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "10.20.33.33:81"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 04 17:00:01 2025 UTC |
Thank you very much. try { session_set_save_handler($handler, false); session_start(); ..... session_write_close(); // <- close the session manually, I can catch the exception in catch block ..... } catch (Exception $e) { print_r($e); }