What potential issues should be considered when using a recursive function to count files in PHP?

One potential issue when using a recursive function to count files in PHP is the possibility of hitting the maximum recursion depth limit set by PHP. To solve this issue, you can increase the recursion depth limit using the `ini_set` function in PHP.

// Set the maximum recursion depth limit to a higher value
ini_set('xdebug.max_nesting_level', 1000);

// Your recursive function to count files
function countFiles($dir) {
    $count = 0;
    $files = scandir($dir);
    
    foreach($files as $file) {
        if ($file != '.' && $file != '..') {
            if (is_dir($dir . '/' . $file)) {
                $count += countFiles($dir . '/' . $file);
            } else {
                $count++;
            }
        }
    }
    
    return $count;
}

// Call the recursive function
$directory = '/path/to/directory';
echo countFiles($directory);