Bug #75215 [NEW]: set_exception_handler callable not called on exception
| From: | bkfake-php at yahoo dot com | Date: | Sun, 17 Sep 2017 03:45:20 +0000 |
| Subject: | Bug #75215 [NEW]: set_exception_handler callable not called on exception | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-211190@lists.php.net to get a copy of this message | ||
From: bkfake-php at yahoo dot com
Operating system: OSX
PHP version: 7.0.23
Package: *General Issues
Bug Type: Bug
Bug description:set_exception_handler callable not called on exception
Description:
------------
exception handler is never called!
it appears to me that the exception itself causes the destruction of the
object.. which calls exit. this somehow bypasses the exception handler.
yet, shutdown function is called!
also note: error_get_last() inside the shutdown function returns null..
this is usually where you can catch fatal error (including the fatal
error: "uncaught exception").
Here the exception was completely swallowed and never reported
PHP's OOP destructor documentation includes this brief
"Calling exit() in a destructor will prevent the remaining shutdown
routines from executing."
a) shutdown function was called, which seems to contradict
documentation
b) no mention of of exception handler... which seems like it should
have been called before the destruction of the objects!
same behavior in 5.6 and 7.0
Test script:
---------------
<?php
class Test
{
public function myMethod()
{
echo __METHOD__.'<br />';
echo 'throwing exception<br />';
throw new Exception('hello world?');
}
public function __destruct()
{
echo __METHOD__.'<br />';
exit;
}
}
class Wrapper
{
public function doIt()
{
$test = new Test();
$test->myMethod();
}
public function __destruct()
{
echo __METHOD__.'<br />';
}
}
register_shutdown_function(function () {
echo 'shutdown function<br />';
echo 'error_get_last: '.json_encode(error_get_last()).'<br />';
});
set_exception_handler(function ($e) {
echo 'exception handler: '.$e->getMessage().'<br />';
});
echo 'Main<br />';
$wrapper = new Wrapper();
$wrapper->doIt();
Expected result:
----------------
exception handler should be called?!
output should include "exception handler: hello world?"
Actual result:
--------------
exception not caught. exception "swallowed" and script exits sans error
with http 200
Test script outputs
Main
Test::myMethod
throwing exception
Test::__destruct
shutdown function
error_get_last: null
Wrapper::__destruct
--
Edit bug report at https://bugs.php.net/bug.php?id=75215&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75215&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75215&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75215&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75215&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75215&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75215&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75215&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75215&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75215&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75215&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75215&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75215&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75215&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75215&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75215&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75215&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75215&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75215&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75215&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75215&r=mysqlcfg