framework: [PHP 7] Exception error PHP 7

I got error in app/Exeptions/Handler.php
Just testing on PHP and don`t know where report issues about PHP 7 Error I have: Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception, instance of TypeError given, called in

This error where thrown when I make typo in controller return view(‘notices,create’); P.S. Any way Laravel good prepared for PHP7. I test for 2 week now and only this issue ))

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 35 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Here’s my take, for laravel 4.2. Couldn’t pass the $previous parameter since Whoops also expects Exception instead of Throwable, so this limits the usefulness of the error message, but it sure beats something that looks like an internal error.

--- a/laravel/framework/src/Illuminate/Exception/Handler.php
+++ b/laravel/framework/src/Illuminate/Exception/Handler.php
@@ -143,6 +143,16 @@
         */
        public function handleException($exception)
        {
+               if ( ! $exception instanceof Exception) {
+                       $exception = new ErrorException(
+                               $exception->getMessage(),
+                               $exception->getCode(),
+                               E_ERROR,
+                               $exception->getFile(),
+                               $exception->getLine()
+                       );
+               }
+
                $response = $this->callCustomHandlers($exception);

                // If one of the custom error handlers returned a response, we will send that

I know the combination of laravel 4.2 and php7 is unsupported, but if this patch is okay, can I PR it?

hello i got some error on php7 that may be related to this issue

Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception, instance of Error given

FatalErrorException in Handler.php line 25: Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception, instance of Error given, called in D:\xampp\htdocs\test\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php on line 73 and defined in D:\xampp\htdocs\test\app\Exceptions\Handler.php:25
Stack trace:
#0 D:\xampp\htdocs\test\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(73): App\Exceptions\Handler->report(Object(Error))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Error))
#2 {main}
thrown

have you seen this error?

After research look like need use “Throwable” instead or for support php5 to try { // Code that may throw an Exception or Error. } catch (Throwable $t) { // Executed only in PHP 7, will not match in PHP 5.x } catch (Exception $e) { // Executed only in PHP 5.x, will not be reached in PHP 7 }

While I’m upgrading our system to the 5.1LTS version, for the time being I catch the throwables in the index.php and artisan files and re-throw them as exceptions.

/** @todo Upgrade to laravel 5.1 to fix this!! */
try {
    $app = require_once __DIR__.'/../bootstrap/start.php';
    $app->run();
} catch(Throwable $e) {
    throw new \Exception($e->getMessage()."\n".$e->getTraceAsString(), $e->getCode());
}

If using Laravel 4.2, upgrade to Laravel 4.2.20. It resolves PHP 7 issues.

i had same problem in laravel 5.1. After reading this issue, i found out i was using laravel v5.1.0 and that seemed wrong so changed 5.1.0 to 5.1.* and ran composer update. this solved the issue for me.