Include Files

Include files

Sometimes, it is good to extracts functions, classes, constants and common initialisations to a separate file that can be included in many files, avoiding to rewrite the same code.

can be used in more than one file. Other times, it is good practice to extract a list of constants or operations common to several scripts to a separate script and inclusion of files. 

require files

require files are like include files except the script will not execute if the file is missing. Declared like this:

require('filename.php');

Avoid the inclusion of a file more than once.

Sometimes, because of the way code is written, a file will be included more than once (like a header) and it may hinder the execution of the script, give bad results or simply look ugly. include and require functions have a similar function which keeps track if the files has been included or not: include_once and require_once respectively