[英]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.