What are the potential pitfalls of using $PHP_SELF in file path generation in PHP?

Using $PHP_SELF in file path generation can potentially introduce security vulnerabilities such as path traversal attacks. It is recommended to use $_SERVER['SCRIPT_NAME'] instead, as it provides a safer way to get the current script's path.

$script_path = $_SERVER['SCRIPT_NAME'];
echo "Current script path: " . $script_path;