How can a Whitelist be used to enhance security when mapping GET parameters to functions in PHP?

When mapping GET parameters to functions in PHP, it is important to use a Whitelist approach to enhance security. This means defining a list of allowed parameters and only allowing those specified in the Whitelist to be passed to the function. This helps prevent malicious input from being processed and reduces the risk of security vulnerabilities such as SQL injection or code execution.

// Define a Whitelist of allowed parameters
$allowedParams = ['param1', 'param2', 'param3'];

// Check if the GET parameter is in the Whitelist
if (isset($_GET['param']) && in_array($_GET['param'], $allowedParams)) {
    // Call the function with the sanitized parameter
    myFunction($_GET['param']);
} else {
    // Handle invalid input
    echo "Invalid parameter";
}

// Function to process the parameter
function myFunction($param) {
    // Process the parameter
    echo "Parameter: " . $param;
}