What are the potential pitfalls of using references in PHP functions?

One potential pitfall of using references in PHP functions is that it can lead to unexpected side effects or unintended changes to variables outside of the function. To avoid this, it is important to clearly document when references are being used and ensure that they are necessary for the intended functionality of the function. Additionally, using references can make the code harder to read and understand, so it is important to use them judiciously.

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

$number = 5;
increment($number);
echo $number; // Output: 6