Fatal error: Uncaught TypeError: filter_var(): Argument #3 ($options) must be of type array

Viewed 5751

previous question: get_magic_quotes_gpc() returns undefined in my code

So then..

I fixed the problem of:

Fatal error: Cannot declare class CI_Log, because the name is already in use in D:\xampp\htdocs\system\libraries\Log.php on line 27 (line 27) class CI_Log {

In this way:

/**
* Error Logging Interface
*
* We use this as a simple mechanism to access the logging
* class and send messages to be logged.
*
* @access   public
* @return   void
*/
if ( ! function_exists('log_message'))
{
    function log_message($level = 'error', $message, $php_error = FALSE)
    {
        static $_log;

        if (config_item('log_threshold') == 1)
        {
            return;
        }

        $_log =& load_class('Log');
        $_log->write_log($level, $message, $php_error);
    }
}

I changed

"if (config_item ('log_threshold') == 0)"

to

"if (config_item ('log_threshold') == 1)"

inside the Common.php file

in

D:\xampp\htdocs\system\core\Common.php

but now there are new errors..

Fatal error: Uncaught TypeError: filter_var(): Argument #3 ($options) must be of type array|int, string given in
D:\xampp\htdocs\system\core\Input.php:391
Stack trace:
_______________________________________________________________________________
#0 D:\xampp\htdocs\system\core\Input.php(391): filter_var('127.0.0.1', 275, '')

        // First check if filter_var is available
        if (is_callable('filter_var'))
        {
            switch ($which) {
                case 'ipv4':
                    $flag = FILTER_FLAG_IPV4;
                    break;
                case 'ipv6':
                    $flag = FILTER_FLAG_IPV6;
                    break;
                default:
                    $flag = '';
                    break;
            }

            return (bool) filter_var($ip, FILTER_VALIDATE_IP, $flag);
        }
_______________________________________________________________________________
#1 D:\xampp\htdocs\system\core\Input.php(354): CI_Input->valid_ip('127.0.0.1') 
if ( ! $this->valid_ip($this->ip_address))
_______________________________________________________________________________
#2 D:\xampp\htdocs\application\models\cms_model.php(32): CI_Input->ip_address()
        if(!$this->input->is_ajax_request() && !isset($_GET['is_json_ajax']))
        {
            $this->db->query("INSERT INTO visitor_log(`date`, `ip`) VALUES(?, ?)", array(date("Y-m-d"), $this->input->ip_address()));
        } 
_______________________________________________________________________________
#3 D:\xampp\htdocs\application\models\cms_model.php(24): Cms_model->logVisit()
        $this->logVisit();
_______________________________________________________________________________
#4 D:\xampp\htdocs\system\core\Loader.php(303): Cms_model->__construct()
            $CI->$name = new $model();
_______________________________________________________________________________
#5 D:\xampp\htdocs\application\third_party\MX\Loader.php(192): CI_Loader->model('Cms_model', 'cms_model', false)
            /* check application & packages */
            parent::model($model, $object_name, $connect);
_______________________________________________________________________________
#6 D:\xampp\htdocs\application\libraries\realms.php(42): MX_Loader->model('cms_model')
        // Get the realms
        $this->CI->load->model('cms_model');
_______________________________________________________________________________
#7 D:\xampp\htdocs\system\core\Loader.php(1099): Realms->__construct()
        {
            $CI->$classvar = new $name;
        }
_______________________________________________________________________________
#8 D:\xampp\htdocs\system\core\Loader.php(975): CI_Loader->_ci_init_class('realms', '', NULL, NULL)
                return $this->_ci_init_class($class, '', $params, $object_name);
_______________________________________________________________________________
#9 D:\xampp\htdocs\application\third_party\MX\Loader.php(155): CI_Loader->_ci_load_class('Realms', NULL, NULL)
            $this->_ci_load_class($library, $params, $object_name);
_______________________________________________________________________________
#10 D:\xampp\htdocs\system\core\Loader.php(1178): MX_Loader->library('realms')
            {
                $this->library($item);
            }
_______________________________________________________________________________
#11 D:\xampp\htdocs\system\core\Loader.php(152): CI_Loader->_ci_autoloader()
    /**
     * Initialize the Loader
     *
     * This method is called once in CI_Controller.
     *
     * @param   array
     * @return  object
     */
    public function initialize()
    {
        $this->_ci_classes = array();
        $this->_ci_loaded_files = array();
        $this->_ci_models = array();
        $this->_base_classes =& is_loaded();

        $this->_ci_autoloader();

        return $this;
    }
_______________________________________________________________________________
#12 D:\xampp\htdocs\application\third_party\MX\Loader.php(59): CI_Loader->initialize()
    /** Initialize the loader variables **/
    public function initialize($controller = NULL) {
        
        if (is_a($controller, 'MX_Controller')) {   
            
            /* reference to the module controller */
            $this->controller = $controller;
            
            /* references to ci loader variables */
            foreach (get_class_vars('CI_Loader') as $var => $val) {
                if ($var != '_ci_ob_level') {
                    $this->$var =& CI::$APP->load->$var;
                }
            }
            
        } else {
            parent::initialize();
        }
_______________________________________________________________________________
#13 D:\xampp\htdocs\system\core\Controller.php(51): MX_Loader->initialize()
    public function __construct()
    {
        self::$instance =& $this;
        
        // Assign all the class objects that were instantiated by the
        // bootstrap file (CodeIgniter.php) to local class variables
        // so that CI can run as one big super object.
        foreach (is_loaded() as $var => $class)
        {
            $this->$var =& load_class($class);
        }

        $this->load =& load_class('Loader', 'core');

        $this->load->initialize();
        
        log_message('debug', "Controller Class Initialized");
    }
_______________________________________________________________________________
#14 D:\xampp\htdocs\application\third_party\MX\Base.php(55): CI_Controller->__construct()
class CI extends CI_Controller
{
    public static $APP;
    
    public function __construct() {
        
        /* assign the application instance */
        self::$APP = $this;
        
        global $LANG, $CFG;
        
        /* re-assign language and config for modules */
        if ( ! is_a($LANG, 'MX_Lang')) $LANG = new MX_Lang;
        if ( ! is_a($CFG, 'MX_Config')) $CFG = new MX_Config;
        
        parent::__construct();
    }
}
_______________________________________________________________________________
#15 D:\xampp\htdocs\application\third_party\MX\Base.php(60): CI->__construct()
/* create the application object */
new CI;
_______________________________________________________________________________
#16 D:\xampp\htdocs\application\third_party\MX\Controller.php(4): require('D:\\xampp\\htdocs...')
/** load the CI class for Modular Extensions **/
require dirname(__FILE__).'/Base.php';
_______________________________________________________________________________
#17 D:\xampp\htdocs\application\third_party\MX\Modules.php(119): include_once('D:\\xampp\\htdocs...')
        /* autoload Modular Extensions MX core classes */
        if (strstr($class, 'MX_') AND is_file($location = dirname(__FILE__).'/'.substr($class, 3).EXT)) {
            include_once $location;
            return;
        }
_______________________________________________________________________________
#18 D:\xampp\htdocs\application\modules\news\controllers\news.php(3): Modules::autoload('MX_Controller')
class News extends MX_Controller
_______________________________________________________________________________
#19 D:\xampp\htdocs\system\core\CodeIgniter.php(249): include('D:\\xampp\\htdocs...')
    include(APPPATH.'controllers/'.$RTR->directory.$RTR->class.'.php');
_______________________________________________________________________________
#20 D:\xampp\htdocs\index.php(228): require_once('D:\\xampp\\htdocs...')
require_once BASEPATH.'core/CodeIgniter.php';
_______________________________________________________________________________
#21 {main} thrown in D:\xampp\htdocs\system\core\Input.php on line 391

I'm not an experienced programmer, I'm a novice.

I fixed something by intuition, because intuition is my dominant skill, but intuition can help me up to a certain point, I need the experience and knowledge of those who know more than me, not only for fix this problem, but also to improve myself, it would be really appreciated if someone is kind enough to help me out of this flood of bugs to restore my site, thank you..

1 Answers

Changing the default part of the switch statement to the following should resolve it:

switch ($which) {
    case 'ipv4':
        $flag = FILTER_FLAG_IPV4;
        break;
    case 'ipv6':
        $flag = FILTER_FLAG_IPV6;
        break;
    default:
        $flag = FILTER_DEFAULT;
        break;
}

Seems it must be a bug in an old version of CodeIgniter. In the "default" case of the switch statement, it's passing an empty string as the 3rd argument to filter_var but it has to receive an array or int.

It's probably only started causing a fatal error on PHP 8 because 8 introduced type hinting for mixed types: https://www.php.net/manual/en/language.types.declarations.php

mixed is equivalent to the union type array|bool|callable|int|float |object|resource|string|null . Available as of PHP 8.0.0.

You can see what's happening on the different versions of PHP using this tool: https://3v4l.org/Sd6oS

EDIT - that probably won't fix all your errors but may be best to get past that one first and see what you're left with.

Related