diff --git a/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php b/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php index ced85fea5058..97e138a4b65b 100644 --- a/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php +++ b/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php @@ -42,11 +42,7 @@ public function bootstrap(Application $app) error_reporting(-1); - set_error_handler([$this, 'handleError']); - - set_exception_handler([$this, 'handleException']); - - register_shutdown_function([$this, 'handleShutdown']); + HandleExceptionsGlobal::register($this); if (! $app->environment('testing')) { ini_set('display_errors', 'Off'); diff --git a/src/Illuminate/Foundation/Bootstrap/HandleExceptionsGlobal.php b/src/Illuminate/Foundation/Bootstrap/HandleExceptionsGlobal.php new file mode 100644 index 000000000000..2f4aed0d7ca3 --- /dev/null +++ b/src/Illuminate/Foundation/Bootstrap/HandleExceptionsGlobal.php @@ -0,0 +1,79 @@ +handler = $handler; + } + + /** + * Report PHP deprecations, or convert PHP errors to ErrorException instances. + * + * @param int $level + * @param string $message + * @param string $file + * @param int $line + * @param array $context + * @return void + * + * @throws \ErrorException + */ + public function handleError($level, $message, $file = '', $line = 0, $context = []) + { + $this->handler->handleError($level, $message, $file, $line, $context); + } + + /** + * Handle an uncaught exception from the application. + * + * Note: Most exceptions can be handled via the try / catch block in + * the HTTP and Console kernels. But, fatal error exceptions must + * be handled differently since they are not normal exceptions. + * + * @param \Throwable $e + * @return void + */ + public function handleException(Throwable $e) + { + $this->handler->handleException($e); + } + + /** + * Handle the PHP shutdown event. + * + * @return void + */ + public function handleShutdown() + { + $this->handler->handleShutdown(); + } +} diff --git a/tests/Support/SupportJsTest.php b/tests/Support/SupportJsTest.php index 3b19e9721662..f3518c5d9ee8 100644 --- a/tests/Support/SupportJsTest.php +++ b/tests/Support/SupportJsTest.php @@ -53,7 +53,7 @@ public function testJsonSerializable() public $bar = 'not world'; - public function jsonSerialize() + public function jsonSerialize(): array { return ['foo' => 'hello', 'bar' => 'world']; } @@ -85,7 +85,7 @@ public function toJson($options = 0) return json_encode(['foo' => 'hello', 'bar' => 'world'], $options); } - public function jsonSerialize() + public function jsonSerialize(): array { return ['foo' => 'not hello', 'bar' => 'not world']; }