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!