__FILE__
__FILE__ holds the current file name.
The file name includes its absolute path, e.g. /tmp/path/to/file.txt. It also uses the file’s actual case.
When used without a file, aka in the command line, __FILE__ contains Command line code.
__FILE__ is often used with __LINE__, which holds the line number.
__FILE__ is also often used with __DIR__, which holds the directory of the file. It is akin to using dirname() on __FILE__.
This constant is written in uppercase, by convention. It is case-insensitive, and may be used with any combination of uppercase and lowercase.
<?php
function trumpet() {
echo __FILE__; // /tmp/test.php
}
trumpet();
?>
See Also
- PHP’s Magic Constants: LINE, FILE, FUNCTION, CLASS, and METHOD
- PHP Magic Constants - Examples of How Magic Constants Work in PHP