What potential pitfalls should be considered when using references in PHP functions?

When using references in PHP functions, it is important to be cautious of unintended side effects that may occur when modifying the original variable passed by reference. It is also crucial to ensure that the reference variable is properly initialized before use to avoid errors. Additionally, be mindful of potential memory leaks or unexpected behavior that may arise from incorrect handling of references.

// Example of using references in PHP functions with caution
function modifyArray(&$arr) {
    // Check if the array is initialized
    if (!is_array($arr)) {
        $arr = array(); // Initialize the array if not already done
    }
    
    // Modify the array safely
    $arr[] = 'new element';
}

// Usage of the function
$array = null;
modifyArray($array);
var_dump($array); // Output: array(1) { [0]=> string(11) "new element" }