【问题标题】:Upgrade from laravel 5 to laravel 5.5 caused an error Argument 1 passed to App\Exceptions\Handler::report()从 laravel 5 升级到 laravel 5.5 导致错误参数 1 传递给 App\Exceptions\Handler::report()
【发布时间】:2019-02-20 12:32:32
【问题描述】:

我们正在尝试将我们的 laravel 5.0 项目升级到最新版本的 laravel(laravel 5.5 也可以)以支持 php7.1。当我们运行 composer install laravel 时会出现以下错误:

[Symfony\Component\Debug\Exception\FatalErrorException] 未捕获的 TypeError:传递给 App\Exceptions\Handler::report() 的参数 1 必须是 Exception 的实例,instanc 给出的错误 e,在 C:\xampp7\htdocs\V.E.K. 中调用。 Lexmond\vendor\laravel\framework\src\Illuminate\Foundation\Boot strap\HandleExceptions.php 在第 73 行并在 C:\xampp7\htdocs\V.E.K. 中定义。 Lexmond\app\Exceptions\Handler.php:25 堆栈跟踪: #0 C:\xampp7\htdocs\V.E.K. Lexmond\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.ph p(73): App\Exceptions\Handler->report(Object(Error)) #1 [内部函数]:Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Error)) #2 {主要} 扔了

这个错误的原因是什么?我们希望任何人都能解决我们的问题。

提前谢谢你!

微信

【问题讨论】:

  • 你能贴出你的 app\Exceptions\Handler.php 代码吗?
  • 在下面查看我的文件
  • 您是否按照升级说明进行操作? laravel.com/docs/5.7/upgrade
  • 是的,但是在 composer install 上已经失败了

标签: php laravel laravel-5


【解决方案1】:
<?php

/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/

$app = new Illuminate\Foundation\Application(
    realpath(__DIR__.'/../')
);

/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/

$app->singleton(
    'Illuminate\Contracts\Http\Kernel',
    'App\Http\Kernel'
);

$app->singleton(
    'Illuminate\Contracts\Console\Kernel',
    'App\Console\Kernel'
);

$app->singleton(
    'Illuminate\Contracts\Debug\ExceptionHandler',
    'App\Exceptions\Handler'
);

/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/

return $app;

【讨论】:

    【解决方案2】:

    处理程序.php

    使用异常; 使用 Illuminate\Foundation\Exceptions\Handler 作为 ExceptionHandler;

    类处理程序扩展了 ExceptionHandler {

    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
        'Symfony\Component\HttpKernel\Exception\HttpException'
    ];
    
    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception  $e
     * @return void
     */
    public function report(Exception $e)
    {
        return parent::report($e);
    }
    
    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $e
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {
        return parent::render($request, $e);
    }
    

    }

    【讨论】:

      【解决方案3】:

      你能发布你在 bootstrap/app.php 中的内容吗?

      还要检查你在那个文件中是否有这个

      $app->singleton(
      Illuminate\Contracts\Debug\ExceptionHandler::class,
      App\Exceptions\Handler::class
      

      );

      【讨论】:

      • 在下面查看我的评论
      猜你喜欢
      • 2020-10-10
      • 2020-12-20
      • 2018-03-12
      • 2021-10-09
      • 2018-06-17
      • 2018-07-13
      • 2018-07-02
      相关资源
      最近更新 更多