The difference between PHP functions require and include are simply error handling. See the quick view table here.
The following table shows what happens when a file is missing. This question gets answered a lot, so I will just solidly state it:
|include()||missing file throws Warning and keeps going||can call same file more than once|
|include_once()||missing file throws Warning and keeps going||cannot call same file more than once|
|require()||missing file throws Fatal Error and stops script||can call same file more than once|
|require_once()||missing file throws Fatal Error and stops script||cannot call same file more than once|
Why choose one over the other?
The answer depends on the importance of the file in question. If the file is not critical, using
include_once() will still let your page be displayed and continue without the missing file.
If a missing file could cause more trouble like database issues, then
require_once() will stop your program dead in its tracks.
Solid Tip: Keep in mind that a Fatal Error will display an empty white screen to the user, which may cause them confusion.
This is one of the best answer so far I had read online. No crap, just useful information. Very well
presented. Thanks for sharing with us. Its really helpful for me. Check this link too its also having good collection of php interview question and answer. link is…