Originally created by: mksharmamk
Showing error as mentioned below when we open url http://localhost/c4/
Deprecated: filter_var(): Passing null to parameter [#3] ($options) of type array|int is deprecated in C:\xampp\htdocs\C4\system\HTTP\RequestTrait.php on line 338
Fatal error: Uncaught ErrorException: Function utf8_encode() is deprecated in C:\xampp\htdocs\C4\system\Log\Handlers\ChromeLoggerHandler.php:180 Stack trace: [#0] C:\xampp\htdocs\C4\system\Log\Handlers\ChromeLoggerHandler.php(180): CodeIgniter\Debug\Exceptions->errorHandler(8192, 'Function utf8_e...', 'C:\xampp\htdocs...', 180) [#1] C:\xampp\htdocs\C4\system\Log\Handlers\ChromeLoggerHandler.php(137): CodeIgniter\Log\Handlers\ChromeLoggerHandler->sendLogs() [#2] C:\xampp\htdocs\C4\system\Log\Logger.php(353): CodeIgniter\Log\Handlers\ChromeLoggerHandler->handle('critical', 'Cache unable to...') [#3] C:\xampp\htdocs\C4\system\Common.php(829): CodeIgniter\Log\Logger->log('critical', 'Cache unable to...', Array) [#4] C:\xampp\htdocs\C4\system\Debug\Exceptions.php(128): log_message('critical', 'Cache unable to...', Array) [#5] [internal function]: CodeIgniter\Debug\Exceptions->exceptionHandler(Object(CodeIgniter\Cache\Exceptions\CacheException)) [#6] {main} thrown in C:\xampp\htdocs\C4\system\Log\Handlers\ChromeLoggerHandler.php on line 180
Fatal error: Uncaught ErrorException: Function utf8_encode() is deprecated in C:\xampp\htdocs\C4\system\Log\Handlers\ChromeLoggerHandler.php:180 Stack trace: [#0] C:\xampp\htdocs\C4\system\Log\Handlers\ChromeLoggerHandler.php(180): CodeIgniter\Debug\Exceptions->errorHandler(8192, 'Function utf8_e...', 'C:\xampp\htdocs...', 180) [#1] C:\xampp\htdocs\C4\system\Log\Handlers\ChromeLoggerHandler.php(137): CodeIgniter\Log\Handlers\ChromeLoggerHandler->sendLogs() [#2] C:\xampp\htdocs\C4\system\Log\Logger.php(353): CodeIgniter\Log\Handlers\ChromeLoggerHandler->handle('critical', 'Uncaught ErrorE...') [#3] C:\xampp\htdocs\C4\system\Common.php(829): CodeIgniter\Log\Logger->log('critical', 'Uncaught ErrorE...', Array) [#4] C:\xampp\htdocs\C4\system\Debug\Exceptions.php(128): log_message('critical', 'Uncaught ErrorE...', Array) [#5] C:\xampp\htdocs\C4\system\Debug\Exceptions.php(197): CodeIgniter\Debug\Exceptions->exceptionHandler(Object(ErrorException)) [#6] [internal function]: CodeIgniter\Debug\Exceptions->shutdownHandler() [#7] {main} thrown in C:\xampp\htdocs\C4\system\Log\Handlers\ChromeLoggerHandler.php on line 180
Warm regards,
Originally posted by: reputed-artist
This is a PHP 8.1+ deprecation warning. The issue is that CodeIgniter is passing null to filter_var() which is now deprecated. Here are several ways to fix this:
Solution 1: Update CodeIgniter (Recommended)
This is likely because you're using an older version of CodeIgniter 4. Update to the latest version:
bash
composer update
Solution 2: Temporary Fix - Suppress the Warning
If you can't update immediately, you can suppress the deprecation warning:
Option A: In php.ini
ini
error_reporting = E_ALL & ~E_DEPRECATED
Option B: In your CodeIgniter .env file
env
CI_ENVIRONMENT = production
Option C: In your index.php
php
// Before loading CodeIgniter
error_reporting(E_ALL & ~E_DEPRECATED);
Solution 3: Custom Fix for the Specific File
Create a custom override for the RequestTrait:
Create a custom trait in app/Common/CustomRequestTrait.php:
php