Home » Php » php – Laravel artisan migrate fail

php – Laravel artisan migrate fail

Posted by: admin July 12, 2020 Leave a comment

Questions:

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)

How to&Answers:

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/

Answer:

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);

Answer:

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 );

Answer:

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