简体   繁体   English

从 PHP 7.4 升级到 8 - 致命错误

[英]Upgrading from PHP 7.4 to 8 - fatal error

I can't find the solution to this problem that occurs when I upgrade from PHP 7.4 to 8 on my shared hosting site.当我在共享主机站点上从 PHP 7.4 升级到 8 时,我找不到解决此问题的方法。 Can any of you help me?你们中的任何人都可以帮助我吗?

The message says:消息说:

Fatal error: Cannot declare class XMLParser, because the name is already in use in /home/[...]/commonfunctions.php on line 1015致命错误:无法声明类 XMLParser,因为该名称已在第 1015 行的 /home/[...]/commonfunctions.php 中使用

The code from 1015:来自 1015 的代码:

    class XMLParser 
{
    var $filename;
    var $xml;
    var $data;

//4 lignes to repair php 7
    public function __construct() 
    {
        //nothing
    } 
    
    
    function XMLParser($xml_file)
    {
        $this->filename = $xml_file;
        $this->xml = xml_parser_create();
        xml_set_object($this->xml, $this);
        xml_set_element_handler($this->xml, 'startHandler', 'endHandler');
        xml_set_character_data_handler($this->xml, 'dataHandler');
        $this->parse($xml_file);
    }

    function parse($xml_file)
    {
        if (!($fp = fopen($xml_file, 'r'))) 
        {
            die('Cannot open XML data file: '.$xml_file);
        return false;
        }

        $bytes_to_parse = 512;

        while ($data = fread($fp, $bytes_to_parse)) 
        {
            $parse = xml_parse($this->xml, $data, feof($fp));
       
            if (!$parse) 
            {
                die(sprintf("XML error: %s at line %d",
                xml_error_string(xml_get_error_code($this->xml)),
                   xml_get_current_line_number($this->xml)));
                xml_parser_free($this->xml);
            }
        }

        return true;
    }

    function startHandler($parser, $name, $attributes)
    {
        $data['name'] = $name;
        if ($attributes) 
        {
            $data['attributes'] = $attributes; 
        }
        $this->data[] = $data;
    }

    function dataHandler($parser, $data)
    {
        if ($data = trim($data)) 
        {
            $index = count($this->data) - 1;
            if(isset($this->data[$index]['content'])) 
            $this->data[$index]['content'] .= $data;
            else $this->data[$index]['content'] = $data;
        }
    }

    function endHandler($parser, $name)
    {
        if (count($this->data) > 1) 
        {
            $data = array_pop($this->data);
            $index = count($this->data) - 1; 
            $this->data[$index]['child'][] = $data;
        }
    }
}

Your class is in conflict with a new native class that was introduced in PHP8.您的类与 PHP8 中引入的新本机类冲突。 Here link .这里链接 You need to rename your class otherwise it won't work and also rename everywhere in your code where referencing this class.您需要重命名您的类,否则它将无法工作,并且还要在您的代码中引用此类的任何地方重命名。

That's the explanation of this error message这就是这个错误信息的解释

Fatal error: Cannot declare class XMLParser, because the name is already in use in

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 PHP 5 升级到 PHP 7.4 - Upgrading from PHP 5 to PHP 7.4 从 PHP 7.4 升级到 8.0 后 Joomla 网站出现错误 - Error on Joomla Website after upgrading from PHP 7.4 to 8.0 将 AWS Elastic Beanstalk 从 PHP 5.6 升级到 7.4 导致 .htaccess 日志中出现“php_value”错误 - Upgrading AWS Elastic Beanstalk from PHP 5.6 to 7.4 caused 'php_value' error in .htaccess logs CentOS PHP 7.4 升级 pecl / pear 包时出错 - CentOS PHP 7.4 Error upgrading pecl / pear packages 安装 Brew 后在 MAC 上升级 PHP 7.4 时出错 - Error upgrading PHP 7.4 on MAC after Brew installation php7.4 error PHP 致命错误:Unable to start pcre module in Unknown on line 0 - php7.4 error PHP Fatal error: Unable to start pcre module in Unknown on line 0 从 PHP7.4 切换到 PHP8.1 致命错误:未捕获的错误:尝试在第 93 98 224 232 行的(模板文件)中为 null 分配属性“posts” - Switching from PHP7.4 to PHP8.1 Fatal error: Uncaught Error: Attempt to assign property "posts" on null
in (Templatefile) on line 93 98 224 232 从 PHP7.4 升级 => PHP8,是否可以忽略某些错误 - Upgrading from PHP7.4 => PHP8, is it possible to ignore certain errors 致命错误:composer.lock 是为 PHP 7.4 或更高版本创建的,但当前的 PHP 版本是 7.1.33 - Fatal Error: composer.lock was created for PHP version 7.4 or higher but the current PHP version is 7.1.33 致命错误:composer.lock 是为 PHP 7.4 或更高版本创建的,但当前 PHP 版本是 7.3.11 - Fatal Error: composer.lock was created for PHP version 7.4 or higher but the current PHP version is 7.3.11
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM