What are the potential pitfalls of using call-by-reference in PHP functions?

When using call-by-reference in PHP functions, it can lead to unexpected behavior and make the code harder to understand and maintain. Additionally, it can introduce side effects by modifying variables outside of the function's scope. To avoid these pitfalls, it's recommended to use call-by-value instead, passing variables as arguments to the function.

function addOne($num) {
    $num += 1;
    return $num;
}

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