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

One potential pitfall of using recursive functions in PHP is the risk of causing a stack overflow if the recursion depth becomes too deep. This can happen if the recursive function is called too many times without a proper base case to stop the recursion. To solve this issue, it is important to always include a base case that will terminate the recursion and prevent it from going infinitely deep.

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

// Test the factorial function
echo factorial(5); // Output: 120