Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 829a6b9

Browse files
[Debug] Fix handling of php7 throwables
1 parent 09cc0b2 commit 829a6b9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Symfony/Component/Debug/Debug.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ public static function enable($errorReportingLevel = null, $displayErrors = true
4646
ErrorHandler::register($errorReportingLevel, $displayErrors);
4747
if ('cli' !== PHP_SAPI) {
4848
ExceptionHandler::register();
49+
50+
if (PHP_VERSION_ID >= 70000) {
51+
$exceptionHandler = set_exception_handler(\Closure::bind(function ($throwable) use (&$exceptionHandler) {
52+
if ($throwable instanceof \Exception) {
53+
$exception = $throwable;
54+
} else {
55+
$exception = new \Exception($throwable->getMessage(), $throwable->getCode());
56+
$exception->file = $throwable->getFile();
57+
$exception->line = $throwable->getLine();
58+
$exception->trace = $throwable->getTrace();
59+
}
60+
$exceptionHandler($exception);
61+
}, null, 'Exception'));
62+
}
4963
// CLI - display errors only if they're not already logged to STDERR
5064
} elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
5165
ini_set('display_errors', 1);

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ public function handleFatal()
197197
$exceptionHandler = set_exception_handler(function () {});
198198
restore_exception_handler();
199199

200+
if (PHP_VERSION_ID >= 70000 && $exceptionHandler instanceof \Closure) {
201+
$reflector = new \ReflectionFunction($exceptionHandler);
202+
foreach ($reflector->getStaticVariables() as $exceptionHandler) {
203+
break;
204+
}
205+
}
200206
if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
201207
$level = isset($this->levels[$type]) ? $this->levels[$type] : $type;
202208
$message = sprintf('%s: %s in %s line %d', $level, $error['message'], $error['file'], $error['line']);

0 commit comments

Comments
 (0)