What potential pitfalls should be considered when working with recursive functions in PHP?

One potential pitfall when working with recursive functions in PHP is the risk of causing a stack overflow if the recursion depth becomes too large. To avoid this issue, it's important to carefully track the recursion depth and potentially limit it to a reasonable number.

function recursiveFunction($input, $depth = 0) {
    // Check recursion depth
    if ($depth > 1000) {
        throw new Exception('Recursion limit exceeded');
    }
    
    // Your recursive logic here
    
    // Call the function recursively with incremented depth
    recursiveFunction($input, $depth + 1);
}

// Start the recursive function
recursiveFunction($input);