PHP 异常 CodeIgniter
PHP Exceptions CodeIgniter
我的代码正在生成 ssse 以下错误:
Fatal error: Uncaught TypeError: Argument 1 passed to
CI_Exceptions::show_exception() must be an instance of Exception,
instance of Error given, called in
C:\xampp\htdocs\gog\lib\core\Common.php on line 662 and defined in
C:\xampp\htdocs\gog\lib\core\Exceptions.php:190 Stack trace: #0
C:\xampp\htdocs\gog\lib\core\Common.php(662):
CI_Exceptions->show_exception(Object(Error)) #1 [internal function]:
_exception_handler(Object(Error)) #2 {main} thrown in C:\xampp\htdocs\gog\lib\core\Exceptions.php on line 190
描述的代码行是这些:
function _exception_handler(Throwable $exception)
{
$_error =& load_class('Exceptions', 'core');
$_error->log_exception('error', 'Exception: '.$exception->getMessage(), $exception->getFile(), $exception->getLine());
// Should we display the error?
if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors')))
{
$_error->show_exception($exception); //line 662
}
exit(1); // EXIT_ERROR
}
public function show_exception(Exception $exception) //line 190
{
$templates_path = config_item('error_views_path');
if (empty($templates_path))
{
$templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
}
$message = $exception->getMessage();
if (empty($message))
{
$message = '(null)';
}
if (is_cli())
{
$templates_path .= 'cli'.DIRECTORY_SEPARATOR;
}
else
{
set_status_header(500);
$templates_path .= 'html'.DIRECTORY_SEPARATOR;
}
if (ob_get_level() > $this->ob_level + 1)
{
ob_end_flush();
}
ob_start();
include($templates_path.'error_exception.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
}
有人能指出我的问题吗?
您从 _exception_handler(Throwable $exception)
内呼叫 show_exception(Exception $exception)
。由于前者将 Exception
作为参数,因此您不能像在第 662 行中那样给它一个 Throwable。Exception 实现了 Throwable 接口,但这并不能保证所有 Throwable 都是异常(例如,它们可以是类型Error
).
将 _exception_handler(Throwable $exception)
替换为 _exception_handler(Exception $exception)
,或将 show_exception(Exception $exception)
更改为 show_exception(Throwable $exception)
,并根据需要相应地更改方法体。
没有 CodeIgniter 版本有那个 _exception_handler()
签名。这就是修改库存框架文件时发生的情况。
下载一份最新的 CodeIgniter 并用它替换你的。
我的代码正在生成 ssse 以下错误:
Fatal error: Uncaught TypeError: Argument 1 passed to CI_Exceptions::show_exception() must be an instance of Exception, instance of Error given, called in C:\xampp\htdocs\gog\lib\core\Common.php on line 662 and defined in C:\xampp\htdocs\gog\lib\core\Exceptions.php:190 Stack trace: #0 C:\xampp\htdocs\gog\lib\core\Common.php(662): CI_Exceptions->show_exception(Object(Error)) #1 [internal function]: _exception_handler(Object(Error)) #2 {main} thrown in C:\xampp\htdocs\gog\lib\core\Exceptions.php on line 190
描述的代码行是这些:
function _exception_handler(Throwable $exception)
{
$_error =& load_class('Exceptions', 'core');
$_error->log_exception('error', 'Exception: '.$exception->getMessage(), $exception->getFile(), $exception->getLine());
// Should we display the error?
if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors')))
{
$_error->show_exception($exception); //line 662
}
exit(1); // EXIT_ERROR
}
public function show_exception(Exception $exception) //line 190
{
$templates_path = config_item('error_views_path');
if (empty($templates_path))
{
$templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
}
$message = $exception->getMessage();
if (empty($message))
{
$message = '(null)';
}
if (is_cli())
{
$templates_path .= 'cli'.DIRECTORY_SEPARATOR;
}
else
{
set_status_header(500);
$templates_path .= 'html'.DIRECTORY_SEPARATOR;
}
if (ob_get_level() > $this->ob_level + 1)
{
ob_end_flush();
}
ob_start();
include($templates_path.'error_exception.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
}
有人能指出我的问题吗?
您从 _exception_handler(Throwable $exception)
内呼叫 show_exception(Exception $exception)
。由于前者将 Exception
作为参数,因此您不能像在第 662 行中那样给它一个 Throwable。Exception 实现了 Throwable 接口,但这并不能保证所有 Throwable 都是异常(例如,它们可以是类型Error
).
将 _exception_handler(Throwable $exception)
替换为 _exception_handler(Exception $exception)
,或将 show_exception(Exception $exception)
更改为 show_exception(Throwable $exception)
,并根据需要相应地更改方法体。
没有 CodeIgniter 版本有那个 _exception_handler()
签名。这就是修改库存框架文件时发生的情况。
下载一份最新的 CodeIgniter 并用它替换你的。