In what situations would it be appropriate to redirect to a custom 404 error page when denying access to PHP files?

When denying access to PHP files, it is appropriate to redirect to a custom 404 error page in situations where you want to provide a more user-friendly and informative message to users who attempt to access restricted PHP files. This can help improve the overall user experience and provide clear guidance on why access is denied.

<?php
if (strpos($_SERVER['REQUEST_URI'], '.php') !== false) {
    header("HTTP/1.0 404 Not Found");
    include('404-error.php');
    exit();
}
?>