views:

90

answers:

1
  1. include("somefile.php");
  2. include_once("somefile.php");
  3. require("somefile.php");
  4. require_once("somefile.php");

What is the difference between these?

+5  A: 

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.

Andrew Moore