【问题标题】:Fatal error: Uncaught TypeError: filter_var(): Argument #3 ($options) must be of type array致命错误:未捕获的类型错误:filter_var():参数 #3 ($options) 必须是数组类型
【发布时间】:2021-01-09 14:12:11
【问题描述】:

上一个问题:get_magic_quotes_gpc() returns undefined in my code

那么..

我解决了以下问题:

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 {

这样:

/**
* 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);
    }
}

我变了

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

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

Common.php 文件中

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

但是现在有新的错误..

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

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

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

【问题讨论】:

  • 您使用的是哪个 PHP 版本?
  • 最新XAMPP版本v8.0.0

标签: php codeigniter


【解决方案1】:

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

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

看来这一定是旧版 CodeIgniter 中的一个错误。在 switch 语句的“默认”情况下,它将一个空字符串作为第三个参数传递给filter_var,但它必须接收arrayint

它可能只是在 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

编辑 - 这可能无法修复所有您的错误,但最好先克服那个错误,看看您还剩下什么。

【讨论】:

  • @DottorCox 随意将我的回复标记为答案,如果对您有帮助,请点赞:D
  • 我做到了,但网站写信给我:“感谢您的反馈!声望低于 15 人的投票会被记录下来,但不要更改公开显示的帖子得分。”
  • @BT643我刚刚问了一个新问题,如果你想帮助我,我将不胜感激stackoverflow.com/questions/65800643/…
猜你喜欢
  • 2021-06-14
  • 1970-01-01
  • 1970-01-01
  • 2021-11-27
  • 2019-08-16
  • 2021-07-08
  • 2023-03-30
  • 2019-11-09
  • 2023-01-10
相关资源
最近更新 更多