我的代码生成了以下错误:
致命错误:未捕获的TypeError:参数1传递给 CI_Exceptions :: show_exception()必须是Exception的一个实例, 给出的错误实例,调用 第662行的C:\ xampp \ htdocs \ gog \ lib \ core \ Common.php并在 C:\ xampp \ htdocs \ gog \ lib \ core \ Exceptions.php:190堆栈跟踪:#0 C:\ XAMPP \ htdocs中\高格\ lib中\芯\的common.php(662): CI_Exceptions-> show_exception(对象(错误))#1 [内部函数]: _exception_handler(Object(Error))在第190行的C:\ xampp \ htdocs \ gog \ lib \ core \ Exceptions.php中抛出#2 {main}
所描述的代码行是:
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;
}
有人可以查明我的问题吗?
答案 0 :(得分:1)
没有CodeIgniter版本具有_exception_handler()
签名。这是修改库存框架文件时发生的情况。
下载最新CodeIgniter的新副本,并用它替换你的。
答案 1 :(得分:0)
您从show_exception(Exception $exception)
内拨打_exception_handler(Throwable $exception)
。由于前者使用Exception
作为参数,因此您不能像在第662行中那样给它一个Throwable。异常实现了Throwable接口,但这并不能保证所有Throwable都是Exceptions(例如它们可以是类型) Error
)。
将_exception_handler(Throwable $exception)
替换为_exception_handler(Exception $exception)
,或将show_exception(Exception $exception)
更改为show_exception(Throwable $exception)
,并根据需要相应地更改方法正文。