Home php What makes the "Magic" constant __dir __

What makes the “Magic” constant __dir __




Question itself in __ dir __ This constant points to the directory in which is that?

Answer 1, Authority 100%

This is the directory of the file in which the code is currently executed:

/ var / www / test-app / index.php:
& lt;? php
echo __dir__; // / Var / WWW / Test-App

/ var / www / test-app / subdir / sub-test.php:
& lt;? php
echo __dir__; // / Var / WWW / TEST-APP / Subdir

__ file __ Similarly will return the path to the currently executed file (i.e. Basename (__ File__) === __dir __ )

Answer 2, Authority 44%

__ dir __ Returns the script directory.

For example, you have a script /usr/www/site/html/index.php . You write in it

echo __dir__;

__ dir __ return the path of the folder in which this script is located, / usr / www / site / html

Answer 3

If you put your script on CRON and your paths will be without a constant dir and analogs, then the script does not find the necessary files. Although with manual launch everything will be OK.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions