bug #10854 [Debug] fix handling deprecated warnings and stacked errors turned into exceptions (nicolas-grekas)
This PR was merged into the 2.5-dev branch.
Discussion
----------
[Debug] fix handling deprecated warnings and stacked errors turned into exceptions
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | none
| License | MIT
| Doc PR | none
When no deprecation logger was registered, deprecated warnings were pretended to be handled (`return true`) when in fact there were just ignored. This is the first part fixed by this patch.
The second is in handleFatal(), when a stacked error was turned into an exception, this exception wasn't properly handled. Fixed also.
Commits
-------
95f3276
[Debug] fix handling deprecated warnings and stacked errors turned into exceptions
This commit is contained in:
commit
896a351d0d
@ -154,12 +154,10 @@ class ErrorHandler
|
||||
|
||||
self::$loggers['deprecation']->warning($message, array('type' => self::TYPE_DEPRECATION, 'stack' => $stack));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->displayErrors && error_reporting() & $level && $this->level & $level) {
|
||||
} elseif ($this->displayErrors && error_reporting() & $level && $this->level & $level) {
|
||||
if (self::$stackedErrorLevels) {
|
||||
self::$stackedErrors[] = func_get_args();
|
||||
|
||||
@ -264,22 +262,35 @@ class ErrorHandler
|
||||
gc_collect_cycles();
|
||||
$error = error_get_last();
|
||||
|
||||
while (self::$stackedErrorLevels) {
|
||||
static::unstackErrors();
|
||||
// get current exception handler
|
||||
$exceptionHandler = set_exception_handler('var_dump');
|
||||
restore_exception_handler();
|
||||
|
||||
try {
|
||||
while (self::$stackedErrorLevels) {
|
||||
static::unstackErrors();
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
if ($exceptionHandler) {
|
||||
call_user_func($exceptionHandler, $exception);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->displayErrors) {
|
||||
ini_set('display_errors', 1);
|
||||
}
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
if (null === $error) {
|
||||
return;
|
||||
}
|
||||
|
||||
$type = $error['type'];
|
||||
if (0 === $this->level || !in_array($type, array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE))) {
|
||||
if (!$error || !$this->level || !in_array($error['type'], array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset(self::$loggers['emergency'])) {
|
||||
$fatal = array(
|
||||
'type' => $type,
|
||||
'type' => $error['type'],
|
||||
'file' => $error['file'],
|
||||
'line' => $error['line'],
|
||||
);
|
||||
@ -287,14 +298,8 @@ class ErrorHandler
|
||||
self::$loggers['emergency']->emergency($error['message'], $fatal);
|
||||
}
|
||||
|
||||
if ($this->displayErrors) {
|
||||
// get current exception handler
|
||||
$exceptionHandler = set_exception_handler('var_dump');
|
||||
restore_exception_handler();
|
||||
|
||||
if ($exceptionHandler || self::$fatalHandler) {
|
||||
$this->handleFatalError($exceptionHandler, $error);
|
||||
}
|
||||
if ($this->displayErrors && ($exceptionHandler || self::$fatalHandler)) {
|
||||
$this->handleFatalError($exceptionHandler, $error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,12 +134,12 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
restore_error_handler();
|
||||
|
||||
$handler = ErrorHandler::register(E_USER_DEPRECATED);
|
||||
$this->assertTrue($handler->handle(E_USER_DEPRECATED, 'foo', 'foo.php', 12, array()));
|
||||
$this->assertFalse($handler->handle(E_USER_DEPRECATED, 'foo', 'foo.php', 12, array()));
|
||||
|
||||
restore_error_handler();
|
||||
|
||||
$handler = ErrorHandler::register(E_DEPRECATED);
|
||||
$this->assertTrue($handler->handle(E_DEPRECATED, 'foo', 'foo.php', 12, array()));
|
||||
$this->assertFalse($handler->handle(E_DEPRECATED, 'foo', 'foo.php', 12, array()));
|
||||
|
||||
restore_error_handler();
|
||||
|
||||
@ -162,7 +162,7 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$handler = ErrorHandler::register(E_USER_DEPRECATED);
|
||||
$handler->setLogger($logger);
|
||||
$handler->handle(E_USER_DEPRECATED, 'foo', 'foo.php', 12, array());
|
||||
$this->assertTrue($handler->handle(E_USER_DEPRECATED, 'foo', 'foo.php', 12, array()));
|
||||
|
||||
restore_error_handler();
|
||||
|
||||
|
Reference in New Issue
Block a user