我在PHP 5.6中使用CodeIgniter 3.0.0。
昨天我更新到PHP 7,并开始出现以下错误:-
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
这是CodeIgniter 3.0.0中的一个已知问题,请参阅此处的github问题和下面的changelog:
修复了一个错误(#4137)-:doc:
Error Handling <general/errors>
在PHP 7下打破了新的Error异常。
这是因为set_exception_handler()更改了PHP 7中的行为。
使用Exception类型声明实现在set_exception_handler()中注册的异常处理程序的代码将在引发Error对象时导致致命错误。
如果处理程序需要同时在PHP 5和7上运行,则应从处理程序中删除类型声明,而要迁移到专用于PHP 7的代码可以仅将Throwable替换为Exception类型声明。
<?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) { ... } ?>
升级到3.0.2之后的任何版本都可以解决您的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句