What are some best practices for using references in PHP?

When using references in PHP, it is important to ensure that you are passing variables by reference only when necessary to avoid unintended side effects. Best practices include using references sparingly, clearly documenting when references are used, and avoiding modifying referenced variables in functions unless it is explicitly intended.

// Example of using references in PHP
$value = 10;

function increment(&$num) {
    $num++;
}

increment($value);
echo $value; // Output: 11