Difference between include, require, include_once and require_once
Difference between include, require, include_once and require_once.
Include : This function will try to import a file, however, it may be that this file does not exist because it has been deleted or is misspelled, in that case it will return an error of type Warning. This means that when not finding the file there will be a warning but the script will continue.
Now, the types of errors regardless of whether they are Notice, Warning or Fatal error should not be. In this case the include will not break the script but later it can be paid expensive.
Require : This function is more strict, if the file does not find it throws a Fatal error and there the script is broken.In this case the script is broken on the first line and the second one is never executed.
Include_once : It will do the same as include, if it does not find the file it will return a Warning, the only difference is that the import of the file will do it once, even if the file is called many times.This will load twice and if that function will be called with that file fifty times it will be loaded fifty times as well.Now if we use
include_once: In this case the file will be loaded on the first line, but the second will do nothing, since that file with that name has already been previously loaded on the first line.
Require_once : In this case the same as include_once will happen, require_once will import a file, and this function is called again with the same file will do nothing. But like it requires, not finding the file will break the script with a fatal error.
In all four cases, if the file is not found, it will return an error, Warning in the case of include and include_once and Fatal error in the case of require and require_once.