标题很容易解释:如何确保正常的 PHP 错误(例如尝试输出 undefined variable )。
echo $a; // ErrorException: Undefined variable: a
在 PHP 中,这只是一个错误,但是在 laravel 中,错误会升级为 ErrorException,从而停止执行。我怎样才能禁用这个功能。我试过了
app/Exceptions/Handler.php
protected $dontReport = [
\Illuminate\Auth\AuthenticationException::class,
\Illuminate\Auth\Access\AuthorizationException::class,
\Symfony\Component\HttpKernel\Exception\HttpException::class,
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
\Illuminate\Session\TokenMismatchException::class,
\Illuminate\Validation\ValidationException::class,
\Illuminate\Exception\ErrorException::class, // added this
\ErrorException::class, // and this
];
此问题与 my earlier question 相关,但我想到使用另一种可能效果更好的方法。
我试图实现的是,就像错误一样,代码不会停止执行,而是继续尽可能地运行。
最佳答案
Laravel 使用它自己的自定义错误处理程序。根据PHP manual :
The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE(this type of error probably), E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.
因此 Laravel 无法捕获并处理此类错误。
当脚本停止执行并且 shutdown function 时,错误会转换为 ErrorException
叫做。那时你无能为力。
关于php - 如何使用 Laravel 中的 $dontReport 选项禁用 ErrorException 显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45608638/