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?
__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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With