简体   繁体   中英

difference between require(__DIR__ . '/file.php') and require('file.php')

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!

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__ .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM