Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

__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();

?>

Documentation

See Also