Migration from php 7.4 to php 8.0
Project detail
I need to migrate from php 7.4 to php 8.0 (shared hosting) and am encountering error messages that my limited knowledge does not allow me to solve.
Nota bene: I may show portions of the code but I am not allowed to give access to the site nor to give entire routines. In practice, I will test your proposals and give you the portions of code pointed by the error messages.
For example:
1)
Fatal error: Cannot declare class XMLParser, because the name is already in use in /commonfunctions.php on line 1015
Here is the concerned code:
class XMLParser
{
var $filename;
var $xml;
var $data;
//4 lines 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;
}
}
}
$solution = “”;
$i = 0;
$path_to_file = “include/errors.xml”;
$myFile = new XMLParser($path_to_file);
$size = sizeof($myFile->data[0][‘child’])-1;
for ($i=0; $idata[0][‘child’][$i][‘child’][1][‘content’];
$keys = explode(” “,$keywords);
for ($j=0; $jdata[0][‘child’][$i][‘child’][5][‘content’];
}
}
2)
Deprecated: Required parameter $mode follows optional parameter $values in /commonfunctions.php on line 2119
function BuildSelectControl($field, $value, $values=””, $secondfield=false, $mode)