Reputation: 196
As asked in the title, whats the difference between
require(__DIR__ . '/file.php')
and
require('file.php')
?
(when both files are in the same folder)
Thank you all for your help!
Upvotes: 7
Views: 12191
Reputation: 9508
If you do
require(__DIR__ . '/file.php')
then you are requiring the file with the full pathname. If the file doing this require is required by another file in another directory, this require will always work. On the other hand, if you
require('file.php')
then if the file where this require statement is is required by another file in another directory, this statement will fail.
That is why it is generally good practice to include the __DIR__
.
Upvotes: 12