Are there any best practices or guidelines for handling recursive functions in PHP?

When dealing with recursive functions in PHP, it is important to ensure that there is a proper base case to prevent infinite recursion. Additionally, it is recommended to carefully manage the function's input parameters to avoid unexpected behavior. Lastly, consider optimizing the function to reduce unnecessary calls and improve performance.

function factorial($n) {
    if ($n <= 1) {
        return 1;
    } else {
        return $n * factorial($n - 1);
    }
}

// Example usage
echo factorial(5); // Output: 120