Home > Backend Development > PHP Tutorial > How to Fix the \'Call-time Pass-by-Reference Has Been Removed\' Error in PHP 5.4?

How to Fix the \'Call-time Pass-by-Reference Has Been Removed\' Error in PHP 5.4?

Barbara Streisand
Release: 2024-11-27 03:48:09
Original
690 people have browsed it

How to Fix the

PHP 5.4 Call-time Pass-by-Reference: A Simple Fix Demystified

The PHP error "Fatal error: Call-time pass-by-reference has been removed" arises when variables are passed as references to functions, a practice that is now deprecated in PHP 5.4. This error can be prevalent in legacy code that extensively utilizes references. While rewriting the entire codebase may seem daunting, a simple fix exists to address this issue.

Contrary to popular belief, the reference sign should be included in the function definition, not the function call. In PHP 5.4, using "&" in function calls is deprecated and triggers warning messages. To resolve this, specify the reference in the function definition.

PHP Documentation Guidance

The PHP documentation states: "There is no reference sign on a function call - only on function definitions." This means that the function definition alone establishes pass-by-reference behavior for the argument.

Correct Usage:

Instead of using the deprecated syntax:

myFunc(&$arg); 
Copy after login

Use the following syntax:

myFunc($arg);
Copy after login

In the function definition:

function myFunc(&$arg) { } 
Copy after login

By adhering to these guidelines, you can easily correct the call-time pass-by-reference issue and eliminate the related errors in your code.

The above is the detailed content of How to Fix the \'Call-time Pass-by-Reference Has Been Removed\' Error in PHP 5.4?. 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