What are the potential pitfalls of using recursive functions in PHP, as seen in the provided code example?

Potential pitfalls of using recursive functions in PHP include the risk of causing a stack overflow if the function is called too many times, leading to a fatal error. To prevent this, it is important to set a base case that will stop the recursive calls once a certain condition is met. Additionally, recursive functions can be less efficient than iterative solutions for some problems.

// Recursive function with a base case to prevent stack overflow
function factorial($n) {
    if ($n <= 1) {
        return 1;
    } else {
        return $n * factorial($n - 1);
    }
}

// Usage example
echo factorial(5); // Output: 120