Home >Backend Development >PHP Tutorial >New magic constants in PHP 5.3__DIR___PHP Tutorial
We know that PHP provides a magic constant (magic constant) __FILE__, which is used to point to the currently executing PHP script. But PHP does not directly provide constants for the directory where the script is located. That is to say, if we want to get the directory where the current PHP script is located, we need to use the dirname() function:
$dir =dirname(__FILE__); ?> In PHP5.3, a new constant __DIR__ is added, pointing to the directory where the currently executed PHP script is located. For example, the currently executed PHP file is /www/website/index.php Then __FILE__ is equal to /www/website/index.php And __DIR__ is equal to /www/website Now we want to include files in the current file directory or subdirectory, we can use it directly:
require_once __DIR__ ./path/to/test.inc.php;
?>