What are the potential pitfalls of using recursion in PHP code?

One potential pitfall of using recursion in PHP code is the risk of causing a stack overflow if the recursion depth becomes too deep. This can lead to a fatal error and crash the script. To prevent this, it's important to implement a base case that will stop the recursion once a certain condition is met.

function factorial($n) {
    if ($n <= 1) {
        return 1; // base case
    } else {
        return $n * factorial($n - 1); // recursive call
    }
}

echo factorial(5); // Output: 120