What are the potential pitfalls of using the $_SERVER['PHP_SELF'] variable to determine the current file in PHP navigation?

Using $_SERVER['PHP_SELF'] to determine the current file in PHP navigation can introduce security vulnerabilities such as cross-site scripting attacks. It is recommended to use htmlspecialchars() function to escape the output of $_SERVER['PHP_SELF'] to prevent potential script injections.

$currentFile = htmlspecialchars($_SERVER['PHP_SELF']);
echo "Current file: " . $currentFile;