Laravel 5.2でカスタム例外クラスを作成しました。 laravel 5.4まではうまくいきます。laravel:App Exceptions CustomException :: report()に渡される引数1は、Exceptionのインスタンスである必要があります。
同じカスタム例外クラスをlaravel 5.5で使用しようとすると、次のエラーが発生します。ここで
Type error: Argument 1 passed to App\Utility\Exceptions\CustomException::report() must be an instance of Exception, none given, called in /var/www/html/bubbles/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php on line 102 {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Type error: Argument 1 passed to App\\Utility\\Exceptions\\CustomException::report() must be an instance of Exception, none given, called in /var/www/html/bubbles/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php on line 102 at /var/www/html/bubbles/app/Utility/Exceptions/CustomException.php:39)
私は
<?php
namespace App\Utility\Exceptions;
use Illuminate\Support\Facades\Lang;
use Exception;
class CustomException extends Exception
{
private $error_code = NULL;
private $error_info = NULL;
function __construct($type = NULL, $errors = NULL)
{
$this->error_code = $type['error_code'];
$this->error_info = $errors;
$message = Lang::get('exceptions.'.$this->error_code);
parent::__construct($message, $type['code'], NULL);
}
public function report(Exception $exception)
{
parent::report($exception);
}
public function getErrorCode()
{
return $this->error_code;
}
public function getErrorInfo()
{
return $this->error_info;
}
}
// end of class CustomException
// end of file CustomException.php
を使用してきた独自の例外クラスは、引数は例外のインスタンスでなければなりません投げている理由を誰が私を説明してもらえますか?ありますかどんな助けでも大歓迎です。
私のプログラミング環境は PHP 7.0.1 Laravel 5.5
ありがとう@Sisve。今それは魅力のように動作します:) – lakshmaji