Laravel 工匠迁移失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34568505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:57:08  来源:igfitidea点击:

Laravel artisan migrate fail

phplaravelcomposer-phpmigrateartisan

提问by Jacob Lane

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

我遇到了这个问题: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

PHP 致命错误:未捕获的类型错误:传递给 Illuminate\Exception\WhoopsDisplayer::display() 的参数 1 必须是 Exception 的实例,给出 ParseError 的实例

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

但我不知道如何修复它,我是 laravel 和作曲家等的新手。

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

我正在使用 laravel 4.0(因为我正在关注我朋友的旧教程)

回答by Limon Monte

ParseErrorwas introducedin PHP 7. In other hand you're using Laravel 4 which has no PHP7 support.

ParseError在 PHP 7中引入的。另一方面,您使用的是不支持 PHP7 的 Laravel 4。

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

Laravel 5.1 是第一个支持 PHP 7 的 Laravel 版本。

So, there's 2 solutions:

所以,有2个解决方案:

  1. upgrade Laravel to >= 5.1 (strongly recommend this!)
  2. downgrade PHP to 5.*
  1. 将 Laravel 升级到 >= 5.1(强烈推荐这个!)
  2. 将 PHP 降级到 5.*


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

阅读有关 PHP7 中可抛出异常的更多信息:https://trowski.com/2015/06/24/throwable-exceptions-and-errors-in-php7/

回答by dtbarne

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(...):

找到了一个很好的解决方法来禁用 laravel 错误处理程序。将此添加到您的 app/config/local/app.php 的顶部(就在返回数组(...)之前:

set_error_handler(null);
set_exception_handler(null);

回答by MikeH

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.

还有另一种方法,您可以用自己的方法包装 Laravel 异常处理程序,将新的 Error 类型转换为 Exception 实例,然后再传回 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:

在 config/app.php 的开头,您可以将包装类注册为默认错误处理程序:

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

ErrorWrapper::setPreviousExceptionHandler( $existing );

回答by Dylan Buth

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

Laravel 发布了 4.2.20 解决了这个问题。https://twitter.com/laravelphp/status/791302938027184128