8

I am getting this problem: http://pastebin.com/B5MKqD0T

PHP Fatal error: Uncaught TypeError: Argument 1 passed to Illuminate\Exception\WhoopsDisplayer::display() must be an instance of Exception, instance of ParseError given

But I have no clue how to fix it, I am new to laravel and composer etc.

I am using laravel 4.0 (because I'm following and old tutorial of my friend)

Limon Monte
  • 52,539
  • 45
  • 182
  • 213
Jacob Lane
  • 103
  • 3
  • 8

4 Answers4

17

ParseError was introduced in PHP 7. In other hand you're using Laravel 4 which has no PHP7 support.

Laravel 5.1 is the first version of Laravel to support PHP 7.

So, there's 2 solutions:

  1. upgrade Laravel to >= 5.1 (strongly recommend this!)
  2. downgrade PHP to 5.*

Read more about throwable exceptions in PHP7: https://trowski.com/2015/06/24/throwable-exceptions-and-errors-in-php7/

Limon Monte
  • 52,539
  • 45
  • 182
  • 213
  • how do I downgrade to php 5? – Jacob Lane Jan 02 '16 at 17:27
  • it depends on your OS, specify it so I can help you. – Limon Monte Jan 02 '16 at 17:28
  • I am using windows 10 – Jacob Lane Jan 02 '16 at 17:29
  • I am also using xampp – Jacob Lane Jan 02 '16 at 17:31
  • go to xampp website and download PHP 5.6 release: https://i.imgur.com/BfcfCpl.png – Limon Monte Jan 02 '16 at 17:33
  • I don't know these are real solutions bcs moving from 4.2 to 5.1 is almost impossible. "Create new app instead of upgrading" says documentation. So, it seems only exceptions fails on php7. I forked laravel/framework and changed lines that is related with this error. You can see changes here: https://github.com/shibby/laravel-framework/commit/1ab51571fde84b31d7328e9b9c86033d390187bf I defined it as custom repository on composer. I'm using my 4.2 now bcs of L4 not developing anymore. – tersakyan Jul 09 '16 at 13:46
8

Found a nice work-around to disable the laravel error handler. Add this to the top of your app/config/local/app.php (right before the return array(...):

set_error_handler(null);
set_exception_handler(null);
dtbarne
  • 8,110
  • 5
  • 43
  • 49
  • This is a great solution, if you don't want or can't downgrade to PHP 5.*, as well as an update to Laravel 5.* is too much work – Edwin Krause Feb 05 '18 at 10:13
1

There's another approach where you can wrap the Laravel exception handler with your own, convert the new Error type to an Exception instance before passing back to Laravel.

Create the below class somewhere in your application:

namespace Some\Namespace;

use Error;
use Exception;

class ErrorWrapper
{
    private static $previousExceptionHandler;

    public static function setPreviousExceptionHandler($previousExceptionHandler)
    {
        self::$previousExceptionHandler = $previousExceptionHandler;
    }

    public static function handleException($error)
    {
            if (!self::$previousExceptionHandler) {
                return;
            }

            $callback = self::$previousExceptionHandler;

            if ($error instanceof Error) {
                 $callback(new Exception($error->getMessage(), $error->getCode()));
            }
            else {
                 $callback($error);
           }
      }
}

At the start of config/app.php, you can then register the wrapper class as the default error handler:

$existing = set_exception_handler( 
    ['Some\Namespace\ErrorWrapper', 'handleException']);

ErrorWrapper::setPreviousExceptionHandler( $existing );
MikeH
  • 93
  • 1
  • 5
1

Laravel released 4.2.20 that resolved this issue. https://twitter.com/laravelphp/status/791302938027184128

Dylan Buth
  • 1,648
  • 5
  • 35
  • 57