[Debug] Fix handling of php7 throwables
This commit is contained in:
parent
09cc0b20d5
commit
b032096763
@ -46,6 +46,30 @@ class Debug
|
|||||||
ErrorHandler::register($errorReportingLevel, $displayErrors);
|
ErrorHandler::register($errorReportingLevel, $displayErrors);
|
||||||
if ('cli' !== PHP_SAPI) {
|
if ('cli' !== PHP_SAPI) {
|
||||||
ExceptionHandler::register();
|
ExceptionHandler::register();
|
||||||
|
|
||||||
|
if (PHP_VERSION_ID >= 70000) {
|
||||||
|
$exceptionHandler = set_exception_handler(function ($throwable) use (&$exceptionHandler) {
|
||||||
|
if ($throwable instanceof \Exception) {
|
||||||
|
$exception = $throwable;
|
||||||
|
} else {
|
||||||
|
static $refl = null;
|
||||||
|
|
||||||
|
if (null === $refl) {
|
||||||
|
$refl = array();
|
||||||
|
foreach (array('file', 'line', 'trace') as $prop) {
|
||||||
|
$prop = new \ReflectionProperty('Exception', $prop);
|
||||||
|
$prop->setAccessible(true);
|
||||||
|
$refl[] = $prop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$exception = new \Exception($throwable->getMessage(), $throwable->getCode());
|
||||||
|
foreach ($refl as $prop) {
|
||||||
|
$prop->setValue($exception, $throwable->{'get'.$prop->name}());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$exceptionHandler($exception);
|
||||||
|
});
|
||||||
|
}
|
||||||
// CLI - display errors only if they're not already logged to STDERR
|
// CLI - display errors only if they're not already logged to STDERR
|
||||||
} elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
|
} elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
|
||||||
ini_set('display_errors', 1);
|
ini_set('display_errors', 1);
|
||||||
|
@ -197,6 +197,12 @@ class ErrorHandler
|
|||||||
$exceptionHandler = set_exception_handler(function () {});
|
$exceptionHandler = set_exception_handler(function () {});
|
||||||
restore_exception_handler();
|
restore_exception_handler();
|
||||||
|
|
||||||
|
if (PHP_VERSION_ID >= 70000 && $exceptionHandler instanceof \Closure) {
|
||||||
|
$reflector = new \ReflectionFunction($exceptionHandler);
|
||||||
|
foreach ($reflector->getStaticVariables() as $exceptionHandler) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
|
if (is_array($exceptionHandler) && $exceptionHandler[0] instanceof ExceptionHandler) {
|
||||||
$level = isset($this->levels[$type]) ? $this->levels[$type] : $type;
|
$level = isset($this->levels[$type]) ? $this->levels[$type] : $type;
|
||||||
$message = sprintf('%s: %s in %s line %d', $level, $error['message'], $error['file'], $error['line']);
|
$message = sprintf('%s: %s in %s line %d', $level, $error['message'], $error['file'], $error['line']);
|
||||||
|
Reference in New Issue
Block a user