8000 [Debug] Fix populating error_get_last() for handled silent errors · symfony/symfony@d7e612d · GitHub
[go: up one dir, main page]

Skip to content

Commit d7e612d

Browse files
[Debug] Fix populating error_get_last() for handled silent errors
1 parent 07d2570 commit d7e612d

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,15 @@ private function reRegister($prev)
377377
*/
378378
public function handleError($type, $message, $file, $line)
379379
{
380-
$level = error_reporting() | E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED;
380+
$level = error_reporting();
381+
$silenced = 0 === ($level & $type);
382+
$level |= E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED;
381383
$log = $this->loggedErrors & $type;
382384
$throw = $this->thrownErrors & $type & $level;
383385
$type &= $level | $this->screamedErrors;
384386

385387
if (!$type || (!$log && !$throw)) {
386-
return $type && $log;
388+
return !$silenced && $type && $log;
387389
}
388390
$scope = $this->scopedErrors & $type;
389391

@@ -479,7 +481,7 @@ public function handleError($type, $message, $file, $line)
479481
}
480482
}
481483

482-
return $type && $log;
484+
return !$silenced && $type && $log;
483485
}
484486

485487
/**

src/Symfony/Component/Debug/Tests/ErrorHandlerTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,30 @@ public function testRegister()
6464
}
6565
}
6666

67+
public function testErrorGetLast()
68+
{
69+
$handler = ErrorHandler::register();
70+
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
71+
$handler->setDefaultLogger($logger);
72+
$handler->screamAt(E_ALL);
73+
74+
try {
75+
@trigger_error('Hello', E_USER_WARNING);
76+
$expected = array(
77+
'type' => E_USER_WARNING,
78+
'message' => 'Hello',
79+
'file' => __FILE__,
80+
'line' => __LINE__ - 5,
81+
);
82+
$this->assertSame($expected, error_get_last());
83+
} catch (\Exception $e) {
84+
restore_error_handler();
85+
restore_exception_handler();
86+
87+
throw $e;
88+
}
89+
}
90+
6791
public function testNotice()
6892
{
6993
ErrorHandler::register();

0 commit comments

Comments
 (0)
0