What are potential pitfalls to be aware of when implementing custom routing in PHP?

One potential pitfall to be aware of when implementing custom routing in PHP is the risk of not properly sanitizing user input, which could lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. To mitigate this risk, it is important to validate and sanitize all user input before using it in your routing logic.

// Example of sanitizing user input in a custom routing implementation
$route = $_GET['route'] ?? '';

// Sanitize user input
$sanitizedRoute = filter_var($route, FILTER_SANITIZE_STRING);

// Use the sanitized input in routing logic
switch ($sanitizedRoute) {
    case 'home':
        include 'home.php';
        break;
    case 'about':
        include 'about.php';
        break;
    default:
        include '404.php';
        break;
}