include("somefile.php");include_once("somefile.php");require("somefile.php");require_once("somefile.php");
What is the difference between these?
include("somefile.php");include_once("somefile.php");require("somefile.php");require_once("somefile.php");What is the difference between these?
The difference between include() and require() is that the include() construct will emit a warning if it cannot find a file; this is different behavior from require(), which will emit a fatal error (and stop the execution of the script).
include_once() and require_once() has the exact same behavior than include() and require(), except PHP will check if the file has already been included, and if so, not include (require) it again.
include_once() and require_once() is especially useful in cases where you are including files containing class and/or function definitions. It prevents you from accidentally including the same file twice and causing "double definition" errors.