【问题标题】:Error whille running composer install on PHP 7.2 Ubuntu在 PHP 7.2 Ubuntu 上运行 composer install 时出错
【发布时间】:2019-01-31 15:38:09
【问题描述】:

我在 PHP 7.2 - Laravel 5.1 上的 composer 安装结束时一直收到此错误

> php artisan clear-compiled
PHP Fatal error:  Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception, instance of Error given, called in /home/forge/bheng/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 73 and defined in /home/forge/bheng/app/Exceptions/Handler.php:29
Stack trace:
#0 /home/forge/bheng/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 in /home/forge/bheng/app/Exceptions/Handler.php on line 29
[2019-01-31 10:29:34] production.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception, instance of Error given, called in /home/forge/bheng/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 73 and defined in /home/forge/bheng/app/Exceptions/Handler.php:29
Stack trace:
#0 /home/forge/bheng/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 in /home/forge/bheng/app/Exceptions/Handler.php:29
Stack trace:
#0 {main}  


                                                                                                                                                                                                                                                                                                                                
  [Symfony\Component\Debug\Exception\FatalErrorException]                                                                                                                                                                                                                                                                       
  Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception, instance of Error given, called in /home/forge/bheng/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 73 and defined in /home/forge/bheng/app/Exceptions/Handler.php:29  
  Stack trace:                                                                                                                                                                                                                                                                                                                  
  #0 /home/forge/bheng/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                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                

Script php artisan clear-compiled handling the post-update-cmd event returned with error code 255
┌──[root@bheng]──[/home/forge/bheng] 
└──  

app/Exceptions/Handler.php

<?php namespace App\Exceptions;

use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Database\Eloquent\ModelNotFoundException as ModelNotFoundException;

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;


class Handler extends 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)
    {
        if ($this->isHttpException($e))
        {
            return $this->renderHttpException($e);
        }
        else if($e instanceof NotFoundHttpException)
        {
            return response()->view('missing', [], 404);
        }

        else if($e instanceof ModelNotFoundException )
        {
            return response()->view('layouts.share.errors.model_not_found', [], 404);
        }

        else
        {
            return parent::render($request, $e);
        }
    }
}

详情


我已经尝试了这两个命令

我仍然得到相同的结果。

我怎样才能防止这种情况发生?

【问题讨论】:

标签: php laravel ubuntu laravel-5 laravel-5.1


【解决方案1】:

您可以运行composer install --no-scripts 或composer update --no-scripts 来安装/更新任何软件包,它会跳过运行任何artisan 命令。

然后您可以尝试运行 php artisan clear-compiled 以查看更新是否已解决问题。

如果这不起作用,您应该考虑升级您的应用程序以使用更新的 Laravel 版本,或将 PHP 降级到与您要使用的 Laravel 版本兼容的旧版本。

【讨论】:

  • Niraj,我运行你的两个命令后得到了相同的结果,你知道为什么吗?
  • 安装和更新命令基本相同。您是否仍然遇到同样的错误?
  • 从您的新屏幕截图来看,错误似乎已得到修复。 Nothing to install or update 表示您的软件包都是最新的。然后你运行php artisan clear-compiled,并没有显示你原来的错误。这是否意味着您的问题已得到解决?
猜你喜欢
  • 2019-07-12
  • 2014-01-17
  • 2020-12-11
  • 1970-01-01
  • 2016-06-11
  • 1970-01-01
  • 2018-04-30
  • 2019-06-26
  • 2021-09-20
相关资源
最近更新 更多