Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do some frameworks use a longer include syntax?

It seems the following two code styles do the same job:

require_once './foo.php';
require_once './../bar.php';

require_once __DIR__.'/foo.php';
require_once __DIR__.'/../bar.php';

Clearly, the first form is shorter and cleaner. However, I see the second form in a lot of third party codes. Is there any reason to prefer the second form?

like image 715
Handsome Nerd Avatar asked Mar 10 '23 21:03

Handsome Nerd


1 Answers

__DIR__ is a magic constant, relative to the current script's file. The dot ., however, is relative to the current working directory, that could have been altered by chdir(), for instance.

like image 192
Decent Dabbler Avatar answered Mar 23 '23 21:03

Decent Dabbler