What potential pitfalls can arise from using $PHP_SELF instead of $_SERVER["PHP_SELF"] in PHP scripts?

Using $PHP_SELF instead of $_SERVER["PHP_SELF"] can pose a security risk as it opens up the script to potential Cross-Site Scripting (XSS) attacks. It is recommended to always use $_SERVER["PHP_SELF"] to avoid this vulnerability.

$php_self = htmlentities($_SERVER["PHP_SELF"]);