Are there any common pitfalls to avoid when trying to retrieve the filename of the current file in PHP?

One common pitfall to avoid when trying to retrieve the filename of the current file in PHP is using $_SERVER['SCRIPT_NAME'] which can sometimes return the full path of the file instead of just the filename. To avoid this issue, you can use the basename() function to extract just the filename from the full path.

$currentFile = basename($_SERVER['SCRIPT_NAME']);
echo $currentFile;