Bug #70689 [Opn]: Exception handler does not work as expected.
| From: | yajenyak at yandex dot ru | Date: | Sun, 11 Oct 2015 06:05:32 +0000 |
| Subject: | Bug #70689 [Opn]: Exception handler does not work as expected. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-196522@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70689&edit=1
ID: 70689
User updated by: yajenyak at yandex dot ru
Reported by: yajenyak at yandex dot ru
Summary: Exception handler does not work as expected.
Status: Open
Type: Bug
Package: Scripting Engine problem
-Operating System: Arch Linux 4.2.2
+Operating System: Arch Linux 4.2.2, 64-bit
PHP Version: 7.0.0RC4
Block user comment: N
Private report: N
New Comment:
Updated OS information.
Previous Comments:
------------------------------------------------------------------------
[2015-10-11 03:34:02] yajenyak at yandex dot ru
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 this bug report at https://bugs.php.net/bug.php?id=70689&edit=1