Home >Backend Development >PHP Tutorial >How Can I Fix the PHP 5.4 \'Call-time Pass-by-reference has been removed\' Error?
Fixing PHP 5.4 Call-time Pass-by-Reference Issue
The introduction of PHP 5.4 marked the removal of call-time pass-by-reference, resulting in the dreaded "Call-time pass-by-reference has been removed" error. This error occurs when variables are passed into functions as references in legacy code.
Easy Fix or Complete Rewrite?
There is no easy fix to this issue. The problem stems from the way references are declared in function definitions, not function calls. PHP's documentation states that "There is no reference sign on a function call - only on function definitions."
Rewrite Legacy Code
Since PHP began issuing deprecation errors for call-time pass-by-reference in version 5.3, it is highly recommended to rewrite legacy code to avoid potential compatibility issues in the future.
Example Rewrite
Instead of:
// Wrong way! myFunc(&$arg); // Deprecated pass-by-reference argument function myFunc($arg) { }
Use:
// Right way! myFunc($arg); // pass-by-value argument function myFunc(&$arg) { }
By declaring references in function definitions, you ensure that PHP will pass arguments by reference without the need for deprecated syntax in function calls.
The above is the detailed content of How Can I Fix the PHP 5.4 \'Call-time Pass-by-reference has been removed\' Error?. For more information, please follow other related articles on the PHP Chinese website!