asked on
PHP 7.4.2 Notice: Trying to access array offset on value of type bool
Notice: Trying to access array offset on value of type bool
The line of code is:
$last_name = $end_element['name'];
Could you please help me solve this? I'm attaching the script and the error is in line 26.
Thanks,
Jorge Batres
PageConfig.php
What does the following file contain
require_once ROOT . 'modules/XForm/XmlParser.php';
ASKER
I modified the line with this and the message went away but now the script is showing 2 other lines in another script called Page.php on lines 136 and 151. I'm trying attaching the file here but I don't know how to do it.
$last_name = isset($end_element['name']);
ASKER
this are the contents of XMLParser.php
<?php
/**
* SAX Parser for xml file. Handlers implement in child classes.
*
* @copyright MitriDAT (c) 2005
* @author Yuriy Tumakha <tumakha@gmail.com>
* @since June 06, 2005 10:11
* @version 1.0
*/
class XmlParsers
{
var $_parser;
function XmlParser($encoding = '') // "ISO-8859-1"
{
if ($encoding)
$this->_parser = xml_parser_create($encoding);
else
$this->_parser = xml_parser_create();
xml_set_object($this->_parser, $this);
xml_set_element_handler($this->_parser, "startElement", "endElement");
xml_set_character_data_handler($this->_parser, "characterData");
}
function __destruct()
{
if (!empty($this->_parser)) xml_parser_free($this->_parser);
unset($this->_parser);
}
function startElement($parser, $name, $attrs)
{
//Implement this function in child class.
}
function endElement($parser, $name)
{
//Implement this function in child class.
}
function characterData($parser, $data)
{
//Implement this function in child class.
}
function parse($file)
{
if (!($fp = fopen($file, "r")))
{
die("Could not open XML file '$file'");
}
while ($content = fread($fp, 4096))
{
if (!xml_parse($this->_parser, $content, feof($fp)))
{
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($this->_parser)),
xml_get_current_line_number($this->_parser)));
}
}
}
}//class XmlParser
?>
ASKER
and these are the two new errors:
Notice: Undefined index: name in /httpdocs/calendar/modules/Core/Page.php on line 136
Notice: Undefined index: name in /httpdocs/calendar/modules/Core/Page.php on line 151
$last_name = isset($end_element['name']
Is setting $last_name to either true or false, which is not what your code expects. For some reason, actions property is not being filled with an array. Take a look at your XML config file and make sure that's in the correct format
ASKER
Ok, so I'll revert this line to its original form
$last_name = isset($end_element['name']);
but as far as the other file, I'm lost
ASKER
Thank you Julian Hansen, I applied the line of code you provided and it worked! All the messages went away.
Thank you so much.
I would still be interested to know what the intended purpose of the PageConfig is so that we can properly assess whether the code in the class is doing what it is supposed to.
ASKER
I agree with you, Julian. The fact is that I bought this script back in 2005 from a guy that worked for a company that used to sell PHP forms.
The script wasn't written for me but was actually modified to suit my needs.
I use the same script for two different applications that are somewhat connected, The calendar script and my reservations script.
I would actually like to have the scripts re-written to something lighter and more efficient, as for the last few years, I have been updating all the deprecated features.
If you look at this code:
$end_element = end($this->actions);
$last_name = $end_element['name'];
You're calling end() on $this->actions. This method "returns the value of the last element or FALSE for empty array". The fact that your error states that you're trying to get an index from a boolean tells me that your end() call returned FALSE, indicating that $this->actions is not returning a populated array. At the start of your code you have var $actions = array(), but there's nothing I can see that actually populates it.