Skip to content

Commit

Permalink
[Debug] fix handling deprecated warnings and stacked errors turned in…
Browse files Browse the repository at this point in the history
…to exceptions
  • Loading branch information
nicolas-grekas committed May 5, 2014
1 parent 19db5f7 commit 95f3276
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
47 changes: 26 additions & 21 deletions src/Symfony/Component/Debug/ErrorHandler.php
Expand Up @@ -154,12 +154,10 @@ function ($row) {

self::$loggers['deprecation']->warning($message, array('type' => self::TYPE_DEPRECATION, 'stack' => $stack));
}
}

return true;
}

if ($this->displayErrors && error_reporting() & $level && $this->level & $level) {
return true;
}
} elseif ($this->displayErrors && error_reporting() & $level && $this->level & $level) {
if (self::$stackedErrorLevels) {
self::$stackedErrors[] = func_get_args();

Expand Down Expand Up @@ -264,37 +262,44 @@ public function handleFatal()
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();

if (null === $error) {
return;
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;
}

$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'],
);

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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php
Expand Up @@ -134,12 +134,12 @@ public function testHandle()
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();

Expand All @@ -162,7 +162,7 @@ public function testHandle()

$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();

Expand Down

0 comments on commit 95f3276

Please sign in to comment.