From fa66cb6c00a157b4e2873ad19548ef2c92a6ef70 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 17 Feb 2015 14:42:26 +0200 Subject: [PATCH] Fix #262: Silenced errors won't fill error_get_last() array --- src/Whoops/Run.php | 9 ++++++++- tests/Whoops/RunTest.php | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Whoops/Run.php b/src/Whoops/Run.php index 63469d3..ff1e527 100644 --- a/src/Whoops/Run.php +++ b/src/Whoops/Run.php @@ -302,7 +302,8 @@ class Run * @param string $file * @param int $line * - * @return bool|null + * @return bool + * @throws ErrorException */ public function handleError($level, $message, $file = null, $line = null) { @@ -322,7 +323,13 @@ class Run } else { $this->handleException($exception); } + // Do not propagate errors which were already handled by Whoops. + return true; } + + // Propagate error to the next handler, allows error_get_last() to + // work on silenced errors. + return false; } /** diff --git a/tests/Whoops/RunTest.php b/tests/Whoops/RunTest.php index 053a539..2a4a276 100755 --- a/tests/Whoops/RunTest.php +++ b/tests/Whoops/RunTest.php @@ -346,6 +346,24 @@ class RunTest extends TestCase $this->assertTrue(true); } + /** + * @covers Whoops\Run::handleError + */ + public function testGetSilencedError() + { + $run = $this->getRunInstance(); + $run->register(); + + $handler = $this->getHandler(); + $run->pushHandler($handler); + + @strpos(); + + $error = error_get_last(); + + $this->assertTrue($error && strpos($error['message'], 'strpos()') !== false); + } + /** * @covers Whoops\Run::handleException * @covers Whoops\Run::writeToOutput