# Error handling in php with session_start

- Thread: https://externals.io/message/29130
- Original archive: https://news-web.php.net/php.internals/29130
- Started by Ralph Schindler on 2007-05-02T18:05:40+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #29130 — Ralph Schindler — 2007-05-02T18:05:40+00:00

URL: https://externals.io/message/29130#29130

Instead of reopening a bug report, I figured I'll post it here to get 
better exposure.  Myself (and a few others at Zend) feel like 
http://bugs.php.net/bug.php?id=41253 is most definitely a bug in the 
engine as it relates to ext/session.

What is trying to be accomplished is the following:  If a developer is 
utilizing a class that calls `session_start()`, and something goes wrong, 
I want to be able to gracefully alert the developer.  This means I want 
to catch any warnings (like the warning you get when you try to open an 
unwritable session file), and throw them as exceptions, so far this 
shouldn't be and out of the ordinary request.

Since ext/session gives no reliable way to retrieve session.save_path 
when its not explicitly set, the only way to handle it is via 
error_handlers.

IMO, the engine is not suppose to shutdown the way it does in the 
following example.

Is the the following totally unacceptable to think that this should not 
work as expected?

webdeveloper@webdevelopment ~ $ cat testerror.php
<?

ini_set('session.save_path', '/var/log');

try {
     set_error_handler('save_handler', E_ALL);
     `session_start()`;
     `restore_error_handler()`;
} catch (Exception $e) {
     echo $e->getMessage();
}

echo 'I NEED THIS LINE TO BE RUN REGARDLESS, WITHOUT THROWING A FATAL';

function save_handler($errno, $errmsg)
{
     throw new Exception('Error caught and thrown as exception: ' . 
$errmsg);
}
webdeveloper@webdevelopment ~ $ php testerror.php
Error caught and thrown as exception: `session_start()`: 
open(/var/log/sess_ed8d2518c68c574daf21c42cae51448d, O_RDWR) failed: 
Permission denied (13)I NEED THIS LINE TO BE RUN REGARDLESS WITHOUT 
THROWING A FATAL
Fatal error: Exception thrown without a stack frame in Unknown on line 0
