What are the potential pitfalls of using a switch-case statement to handle multiple file types in PHP?

Using a switch-case statement to handle multiple file types in PHP can lead to code duplication and maintenance issues as each case block may contain similar logic. To solve this, you can create a mapping of file types to corresponding functions or classes, allowing for more modular and maintainable code.

$fileType = 'pdf'; // Example file type

$fileHandlers = [
    'pdf' => function() {
        // Handle PDF file
    },
    'csv' => function() {
        // Handle CSV file
    },
    'txt' => function() {
        // Handle TXT file
    },
];

if (array_key_exists($fileType, $fileHandlers)) {
    $fileHandlers[$fileType]();
} else {
    // Handle unsupported file type
}