更新到PHP 7后,CodeIgniter CI_Exceptions :: show_exception错误 [英] CodeIgniter CI_Exceptions::show_exception error after updating to PHP 7
问题描述
我使用PHP 5.6的CodeIgniter 3.0.0。
昨天我更新到PHP 7并开始收到以下错误: -
未捕获TypeError:传递给CI_Exceptions :: show_exception()的参数1必须是
Exception的实例,给出Error的实例,在/ my / file / path / app / system / core / Common.php在658行,并在/my/file/path/hgx_portal/app/system/core/Exceptions.php:190中定义
堆栈跟踪:
#0 /my/file/path/hgx_portal/app/system/core/Common.php(658):CI_Exceptions-> show_exception(Object
(错误))
#1 [内部函数]: _exception_handler(Object(Error))
#2 {main}
在/my/file/path/hgx_portal/app/system/core/Exceptions.phpon行190中引发
这是CodeIgniter 3.0.0中的一个已知问题,请参阅github问题此处和 changelog 以下:
PHP 7下的新错误异常的错误处理(#4137) - :doc:
错误处理< general / errors>
。
这是因为set_exception_handler()
$ b $ b set_exception_handler()使用Exception的类型声明,
会在抛出Error对象时导致致命错误。
如果处理程序需要同时工作PHP 5和7,你应该从处理程序中删除
类型声明,而正在执行
的代码只能通过Throwable替换为Exception
类型声明。
<?php
// PHP 5时代代码会破解。
function handler(Exception $ e){...}
set_exception_handler('handler');
// PHP 5和7兼容。
function handler($ e){...}
//仅限PHP 7。
function handler(Throwable $ e){...}
?>
升级到3.0.2以外的任何版本都能解决您的问题。 / p>
I was using CodeIgniter 3.0.0 with PHP 5.6.
Yesterday I updated to PHP 7 and started getting following error:-
Uncaught TypeError: Argument 1 passed to CI_Exceptions::show_exception() must be
an instance of Exception, instance of Error given, called in /my/file/path/app/system/core/Common.php on line 658 and defined in /my/file/path/hgx_portal/app/system/core/Exceptions.php:190
Stack trace:
#0 /my/file/path/hgx_portal/app/system/core/Common.php(658): CI_Exceptions->show_exception(Object
(Error))
#1 [internal function]: _exception_handler(Object(Error))
#2 {main}
thrown in /my/file/path/hgx_portal/app/system/core/Exceptions.phpon line 190
This is a know issue in CodeIgniter 3.0.0, see the github issue here and changelog below:
Fixed a bug (#4137) - :doc:
Error Handling <general/errors>
breaks for the new Error exceptions under PHP 7.
It's because set_exception_handler() changed behavior in PHP 7.
Code that implements an exception handler registered with set_exception_handler() using a type declaration of Exception will cause a fatal error when an Error object is thrown.
If the handler needs to work on both PHP 5 and 7, you should remove the type declaration from the handler, while code that is being migrated to work on PHP 7 exclusively can simply replace the Exception type declaration with Throwable instead.
<?php // PHP 5 era code that will break. function handler(Exception $e) { ... } set_exception_handler('handler'); // PHP 5 and 7 compatible. function handler($e) { ... } // PHP 7 only. function handler(Throwable $e) { ... } ?>
Upgrading to anything beyond 3.0.2 will fix your issue.
这篇关于更新到PHP 7后,CodeIgniter CI_Exceptions :: show_exception错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!