Home > Backend Development > PHP Tutorial > How to Fix PHP\'s Deprecated Call-Time Pass-by-Reference Warning?

How to Fix PHP\'s Deprecated Call-Time Pass-by-Reference Warning?

Linda Hamilton
Release: 2024-12-11 04:04:14
Original
167 people have browsed it

How to Fix PHP's Deprecated Call-Time Pass-by-Reference Warning?

DEPRECATED CALL-TIME PASS-BY-REFERENCE IN PHP

A warning has been encountered regarding call-time pass-by-reference, which has been deprecated. This means that the following lines of code are causing the warning:

function XML() {
    $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');
}
Copy after login

Explanation of the Deprecation

Call-time pass-by-reference allows simulating the behavior of passing arguments by reference when they are passed by value. However, this is no longer necessary or recommended.

Additionally, passing objects by reference is also no longer necessary as objects are always modified when passed to functions.

How to Fix the Warning

To resolve the warning, simply remove the & symbols from the variable references. The code should be modified as follows:

function XML() {
    $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');
}
Copy after login

The above is the detailed content of How to Fix PHP\'s Deprecated Call-Time Pass-by-Reference Warning?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template