PHP dirname (__ FILE__) v / s. /

I found this code in a small script that I am modifying for my use:

require dirname(__FILE__)."/GearmanManager.php";

I found it a little strange won't

require "./GearmanManager.php";

do the same?

+4
source share
1 answer

When you use ./, you look in the current working directory, which may change. dirname(__FILE__), on the other hand, will not change.

If you, for example, change the working directory (using chdir('/')or similar) before require, your first example will be successful, while your second will not be executed.

Excerpt from another answer :

However, it is more efficient to explicitly use include./file than PHP, which always checks the current directory for each include.

, , , ./ .

+2

Source: https://habr.com/ru/post/1525001/


All Articles