Bug #70689 [NEW]: Exception handler does not work as expected.

From: Date: Sun, 11 Oct 2015 03:34:03 +0000
Subject: Bug #70689 [NEW]: Exception handler does not work as expected.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196519@lists.php.net to get a copy of this message
From: yajenyak at yandex dot ru Operating system: Arch Linux 4.2.2 PHP version: 7.0.0RC4 Package: Scripting Engine problem Bug Type: Bug Bug description:Exception handler does not work as expected. Description: ------------ When the ErrorException is thrown in the error handler registered with set_error_handler() the exception handler is not called but the next line in the code is executed which not should happend because the exception handler must be called. I can't provide exact chunk of the code because the error is not reproducable without context, but the code that I will provide causes the bug happen in the context. This bug may be related with the https://bugs.php.net/bug.php?id=70210 but I don't have enough knowledge of the PHP internals for now to make conclusions. Test script: --------------- // This error code doesn't reproduce the error without context code, but it shows when the bug happens: class MyHandler { public function handleException(\Throwable $e) { die('This line WILL NOT be called!'); } public function handleError($errno, $errstr, $errfile, $errline, $context) { if ($errno && error_reporting()) { // This line should cause the MyHandler::handleException() be called // but the the die() in the $myCallback is executed instead, // it should not happen! throw new \ErrorException($errstr, 0, $errno, $errfile, $errline); } } public function handleError($errno, $errstr, $errfile, $errline, $context) { die('called'); } } error_reporting(E_ALL | E_STRICT); ini_set('display_errors', 1); $myHandler = new MyHandler; set_error_handler([$myHandler, 'handleError']); set_exception_handler([$myHandler, 'handleException']); register_shutdown_function([$myHandler, 'shutdown']); // ------------------------ // In some method of some class: class MySomeClass { // ... public function doSomething() { // ... $myCallback = function ($name) { die('This line WILL be executed!'); }; foreach ($collection as $item) { // ... try { // Trigger error - E_WARNING $res = $myCallback(); } catch (\Throwable $e) { die('This line WILL NOT be executed'); } die('This line WILL NOT be executed'); // ... // ... } Expected result: ---------------- Calling of the MyHandler::handleException() Actual result: -------------- The die() function is called here: $myCallback = function ($name) { die('This line WILL be executed!'); }; -- Edit bug report at https://bugs.php.net/bug.php?id=70689&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70689&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70689&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70689&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=70689&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=70689&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=70689&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=70689&r=needscript Try newer version: https://bugs.php.net/fix.php?id=70689&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=70689&r=support Expected behavior: https://bugs.php.net/fix.php?id=70689&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=70689&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=70689&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=70689&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70689&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=70689&r=dst IIS Stability: https://bugs.php.net/fix.php?id=70689&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=70689&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=70689&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=70689&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=70689&r=mysqlcfg

« previous php.bugs (#196519) next »