coskun olcucu5,340 Points
include,require,include once and require once
Can someone explain more in details include and require etc?
As stated by Alena in the course here are the differences :
The difference between include and require is what happens if they encounter an error. If you use the include command and the file doesn't exist then PHP will throw a warning. But it will still execute the rest of the code. On the other hand if you use require and the file doesn't exist then PHP will error and will not execute any more code.
The other difference between them is how many times PHP will include the file. If you use include or require on a same file multiple times, it will load that file multiple times. This will work fine for HTML snippets like our header and footer files.
But with other files, like files like create new functions, this would cause an error.
So, to sum up if you use "_once", PHP will look if the file has already been loaded, and if not, It will load it.
include('details.php'); include('details.php'); // The details page 'll be included twice. include('details_second.php'); include_once('details_second.php'); // The details_second page 'll be included once.
If you need some more information feel free to ask once again, we are here to help.