enter image description here

The question itself in __DIR__ , this constant points to the directory in which there is what?

  • one
    and what prevents you from seeing what the constant displays? - Alex
  • Well, yes, but I know FIG, but thanks for kicking in the right direction - user33274

3 answers 3

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

 /var/www/test-app/index.php: <?php echo __DIR__; // /var/www/test-app 

 /var/www/test-app/subdir/sub-test.php: <?php echo __DIR__; // /var/www/test-app/subdir 

__FILE__ similarly return to you the path to the file currently being executed (i.e. basename(__FILE__) === __DIR__ )

  • And in what case is it convenient? - user33274
  • 2
    @LenovoID is a separate question. But in general, in another way it is difficult to find where your current application is located. For example, to load the neighboring script from the parent folder, I can include dirname(__DIR__) . '/script.php' include dirname(__DIR__) . '/script.php' , although this is not a very correct approach. Usually it helps to find the application root once (with the resolution of all symlinks) and sometimes it helps in debugging. - etki
  • Is it similar to writing a full path without these constants? - user33274
  • @LenovoID you physically can not know the full path to run the script. But you can contact __DIR__ . - etki
  • so you can contact him from the lantern? - user33274

__DIR__ returns the directory of the script being executed.

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

 echo __DIR__; 

__DIR__ will return the path of the folder where this script is located, /usr/www/site/html

  • 2
    For example, you have a script /usr/www/site/html/index.php. You write echo __DIR__ , __DIR__ will return the path of the folder where this script is located / usr / www / site / html - Devel0per

If you put your script on cron and you have paths without the constant DIR and analogues, the script will not find the necessary files. although with manual start everything will be ok.