What are the advantages and disadvantages of using glob() to generate a whitelist for PHP file inclusion?

When using glob() to generate a whitelist for PHP file inclusion, the advantage is that it allows you to easily retrieve a list of files matching a specific pattern, which can be useful for creating a whitelist of allowed files. However, the disadvantage is that glob() can potentially return unexpected results if not used carefully, such as including files you did not intend to whitelist.

$whitelist = glob('path/to/whitelisted/files/*.php');
$requested_file = $_GET['file'];

if(in_array($requested_file, $whitelist)) {
    include($requested_file);
} else {
    echo "Access denied.";
}