致命错误:未被捕获的TypeError:filter_var():参数3($ options)必须为数组类型 [英] Fatal error: Uncaught TypeError: filter_var(): Argument #3 ($options) must be of type array

查看:148
本文介绍了致命错误:未被捕获的TypeError:filter_var():参数3($ options)必须为数组类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上一个问题: get_magic_quotes_gpc()返回在我的代码中未定义

那么那么..

我解决了以下问题:

 致命错误:无法声明类CI_Log,因为该名称已在第27行(第27行)的D:\ xampp \ htdocs \ system \ libraries \ Log.php中使用,类CI_Log { 

通过这种方式:

 /***错误记录界面**我们使用它作为一种简单的机制来访问日志记录*类并发送要记录的消息.** @公开访问* @返回无效*/如果(!function_exists('log_message')){函数log_message($ level ='error',$ message,$ php_error = FALSE){静态$ _log;如果(config_item('log_threshold')== 1){返回;}$ _log =&load_class('Log');$ _log-> write_log($ level,$ message,$ php_error);}} 

我改变了

 "如果(config_item('log_threshold')== 0)" 

 "如果(config_item('log_threshold')== 1)" 

Common.php 文件内

 <代码> D:\ xampp \ htdocs \ system \ core \ Common.php 

但是现在有新的错误.

 致命错误:未捕获的TypeError:filter_var():参数3($ options)的类型必须为array | int,字符串形式为D:\ xampp \ htdocs \ system \ core \ Input.php:391堆栈跟踪:_________________________________________________________________________________#0 D:\ xampp \ htdocs \ system \ core \ Input.php(391):filter_var('127.0.0.1',275,'')//首先检查filter_var是否可用如果(is_callable('filter_var')){切换($ which){案例"ipv4":$ flag = FILTER_FLAG_IPV4;休息;案例"ipv6":$ flag = FILTER_FLAG_IPV6;休息;默认:$ flag ='';休息;}返回(布尔)filter_var($ ip,FILTER_VALIDATE_IP,$ flag);}_________________________________________________________________________________#1 D:\ xampp \ htdocs \ system \ core \ Input.php(354):CI_Input-> valid_ip('127.0.0.1')如果(!$ 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("Ym-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 =新的$ model();_________________________________________________________________________________#5 D:\ xampp \ htdocs \ application \ third_party \ MX \ Loader.php(192):CI_Loader-> model('Cms_model','cms_model',false)/*检查应用程序&包*/parent :: model($ model,$ object_name,$ connect);_________________________________________________________________________________#6 D:\ xampp \ htdocs \ application \ libraries \ realms.php(42):MX_Loader-> model('cms_model')//获取领域$ this-> CI-> load-> model('cms_model');_________________________________________________________________________________#7 D:\ xampp \ htdocs \ system \ core \ Loader.php(1099):Realms-> __ construct(){$ CI-> $ classvar =新的$ name;}_________________________________________________________________________________#8 D:\ xampp \ htdocs \ system \ core \ Loader.php(975):CI_Loader-> _ci_init_class('realms','',NULL,NULL)返回$ 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()/***初始化加载程序**此方法在CI_Controller中被调用一次.** @参数数组* @返回对象*/公共函数initialize(){$ this-> _ci_classes = array();$ this-> _ci_loaded_files = array();$ this-> _ci_models = array();$ this-> _base_classes =&is_loaded();$ this-> _ci_autoloader();返回$ this;}_________________________________________________________________________________#12 D:\ xampp \ htdocs \ application \ third_party \ MX \ Loader.php(59):CI_Loader-> initialize()/**初始化加载器变量**/公共函数initialize($ controller = NULL){如果(is_a($ controller,'MX_Controller')){/*引用模块控制器*/$ this-> controller = $ controller;/*对ci加载器变量的引用*/foreach(get_class_vars('CI_Loader')as $ var => $ val){如果($ var!='_ci_ob_level'){$ this-> $ var =&CI :: $ APP-> load-> $ var;}}} 别的 {parent :: initialize();}_________________________________________________________________________________#13 D:\ xampp \ htdocs \ system \ core \ Controller.php(51):MX_Loader-> initialize()公共功能__construct(){self :: $ instance =&$ this;//分配由实例化的所有类对象//将文件(CodeIgniter.php)引导到本地类变量//以便CI可以作为一个大的超级对象运行.foreach(is_loaded()为$ 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()CI类扩展CI_Controller{公共静态$ APP;公共功能__construct(){/*分配应用程序实例*/self :: $ APP = $ this;全局$ LANG,$ CFG;/*为模块重新分配语言和配置*/如果(!is_a($ LANG,'MX_Lang'))$ LANG =新的MX_Lang;if(!is_a($ CFG,'MX_Config'))$ CFG =新的MX_Config;父母:: __ construct();}}_________________________________________________________________________________#15 D:\ xampp \ htdocs \ application \ third_party \ MX \ Base.php(60):CI-> __ construct()/*创建应用程序对象*/新配置项;_________________________________________________________________________________#16 D:\ xampp \ htdocs \ application \ third_party \ MX \ Controller.php(4):require('D:\\ xampp \\ htdocs ...')/**为模块化扩展加载CI类**/需要dirname(__ FILE __).'/Base.php';_________________________________________________________________________________#17 D:\ xampp \ htdocs \ application \ third_party \ MX \ Modules.php(119):include_once('D:\\ xampp \\ htdocs ...')/*自动加载Modular Extensions MX核心类*/if(strstr($ class,'MX_')AND is_file($ location = dirname(__ FILE __).'/'.substr($ class,3).EXT)){include_once $ location;返回;}_________________________________________________________________________________#18 D:\ xampp \ htdocs \ application \ modules \ news \ controllers \ news.php(3):Modules :: autoload('MX_Controller')新闻类扩展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';_________________________________________________________________________________在第391行的D:\ xampp \ htdocs \ system \ core \ Input.php中抛出#21 {main} 

我不是经验丰富的程序员,我是新手.

我通过直觉来固定某些东西,因为直觉是我的主要技能,但是直觉可以帮助我达到一定程度,我需要比我了解更多的人的经验和知识,不仅是为了解决这个问题,而且还需要为了提高自己,如果有人能帮助我摆脱大量的错误来恢复我的网站,我将不胜感激.

解决方案

将switch语句的默认部分更改为以下内容可以解决该问题:

 开关($ which){案例"ipv4":$ flag = FILTER_FLAG_IPV4;休息;案例"ipv6":$ flag = FILTER_FLAG_IPV6;休息;默认:$ flag = FILTER_DEFAULT;休息;} 

似乎它必须是旧版本的CodeIgniter中的错误.在默认"中,对于switch语句,它会将一个空字符串作为第三个参数传递给 filter_var ,但它必须接收一个 array int .

它可能只是开始在PHP 8上引起致命错误,因为8引入了混合类型的类型提示: https://www.php.net/manual/en/language.types.declarations.php

mixed等效于联合类型array | bool | callable | int | float | object | resource | string | null.自PHP 8.0.0起可用.

使用此工具,您可以看到不同版本的PHP上发生了什么: https://3v4l.org/Sd6oS

编辑-可能无法修复所有您的错误,但最好是首先克服该错误,然后看看您留下的内容.

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..

解决方案

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.

这篇关于致命错误:未被捕获的TypeError:filter_var():参数3($ options)必须为数组类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆