zval (Zend Engine value container) as the argument provided by the caller. Instead of creating a copy of the value in the function’s local scope, PHP establishes an alias in the local symbol table that points to the original variable’s memory address. Consequently, any mutations applied to the parameter within the function directly alter the original variable in the calling scope.
Syntax
To declare that a function parameter must be passed by reference, prepend an ampersand (&) to the parameter name in the function signature.
Technical Constraints and Behavior
1. Signature-Level Declaration Passing by reference is strictly defined in the function signature. Call-time pass-by-reference was deprecated in PHP 5.3 and removed in PHP 5.4. The caller simply passes the variable normally, and the engine handles the reference binding based on the function definition. Attempting to pass by reference at call-time results in a compile-time syntax error.Returning by Reference
PHP also supports returning by reference, which allows a function to return a pointer to a variable rather than its value. This requires the ampersand (&) in two places: before the function name in the declaration, and before the function call during assignment.
Unsetting References
Using theunset() construct on a reference parameter inside a function does not destroy the original variable in the calling scope. It only severs the binding between the local alias in the function’s symbol table and the underlying zval.
Tired of Poor PHP Skills? Fix That With Deep Grasping!Learn More





