'CodeIgniter CI_Exceptions::show_exception error after updating to PHP 7

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


Solution 1:[1]

This error is caused by PHP 7 (which throws Error instead Exception in set_exception_handler function.

If you cannot do an upgrade the CodeIgniter system folder, you can just change the file system/core/Exceptions.php at line 190:

public function show_exception(Exception $exception)

To

public function show_exception($exception)

Solution 2:[2]

Just go to /system/core/Exceptions.php open the file, and then 'save'

It works for me

I use macOS Monterey, PHP 8.1.2

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Silvio Delgado
Solution 2 Kai - Kazuya Ito