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
Barbara StreisandOriginal
2024-11-27 03:48:09640browse

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); 

Use the following syntax:

myFunc($arg);

In the function definition:

function myFunc(&$arg) { } 

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!

Statement:
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