2021-01-30

Argument #1 ($parser) must be passed by reference

Moving from PHP 7.4 to PHP 8.0, I've got a problem with some code throwing a warning. Code works, but I would like to figure out the problem. There were no Warnings in PHP 7.4. Here are the Warnings: (modified to take my info out of the error)

PHP Warning: XML::open(): Argument #1 ($parser) must be passed by reference, value given in .../classes/xml_5.php on line 89

PHP Warning: XML::open(): Argument #1 ($parser) must be passed by reference, value given in .../classes/xml_5.php on line 89

PHP Warning: XML::open(): Argument #1 ($parser) must be passed by reference, value given in .../classes/xml_5.php on line 89

PHP Warning: XML::data(): Argument #1 ($parser) must be passed by reference, value given in .../classes/xml_5.php on line 89

PHP Warning: XML::close(): Argument #1 ($parser) must be passed by reference, value given in .../classes/xml_5.php on line 89

PHP Warning: XML::open(): Argument #1 ($parser) must be passed by reference, value given in .../classes/xml_5.php on line 89

(they keep going on the same)

The code:

    function __construct(){
        $this->parser = xml_parser_create();
        xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
        xml_set_object($this->parser, $this);
        xml_set_element_handler($this->parser, 'open', 'close');
        xml_set_character_data_handler($this->parser, 'data');
    }

    function destruct(){ xml_parser_free($this->parser); }

    function & parse(&$data){
        $this->document = array();
        $this->stack    = array();
        $this->parent   = &$this->document;
        $return_data = xml_parse($this->parser, $data, true) ? $this->document : NULL;     
        return $return_data;
    }

The problem line (89) is at the end, this line:

$return_data = xml_parse($this->parser, $data, true) ? $this->document : NULL;  

I see that in PHP 8 that xml_parse changed: 8.0.0 parser expects an XMLParser instance now; previously, a resource was expected.

I have spent days on this, and I am missing something! Thanks, everyone!



from Recent Questions - Stack Overflow https://ift.tt/3prWUFu
https://ift.tt/eA8V8J

No comments:

Post a Comment