|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-09-17 07:13 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2017-09-17 07:13 UTC] requinix@php.net
[2017-09-17 15:05 UTC] bkfake-php at yahoo dot com
[2017-09-17 15:59 UTC] requinix@php.net
-Summary: set_exception_handler callable not called on
exception
+Summary: Show error if script exits while an exception was
being thrown
-Status: Not a bug
+Status: Open
-Type: Bug
+Type: Feature/Change Request
-Package: *General Issues
+Package: Scripting Engine problem
[2017-09-17 15:59 UTC] requinix@php.net
[2017-09-18 15:24 UTC] bkfake-php at yahoo dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 12:00:01 2025 UTC |
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