10.
Using require to Include Functions
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
2 Comments
Hi there,
Thanks for these great path to PHP.
I'd like to ask you a question regarding to Chapter 10 challenge.
I think there it appears a new concept : the use of "__DIR__." before the files to include.
I've not been able to clarify the reason why use this sentence "__DIR__.".
Which is the criteria to use or no to use this formula before the url of the required file?
Thanks again in advance.
Emma
Hey @emmatr,
Good question! __DIR__ constant is a special *magic* PHP constant that returns the absolute path to the directory of the current file where you write this constant. And it's a good practice to always use absolute paths when include files instead of relative ones. This way PHP knows exactly where the file is and do not search in some common folders - PHP may look into different folders for relative paths. But instead of hardcoding those absolute paths that could be different on different servers, __DIR__ allows you to get it dynamically.
Cheers!
"Houston: no signs of life"
Start the conversation!