PHP: Including PHP Resource Files

include v.s. require

  • include and require only differ in that
    • require -  script will HALT if the file specified is not found
    • include -  script will CONTINUE if the file specified is not found

 

include

include 'include/init.inc.php';
  • include will include the file - even if already included - as an overwrite.
  • Previous variable declarations and functions will be replaced.

 

include_once

include_once 'include/init.inc.php';
  • include_once will ONLY include the file if NOT already included.
  • if file already included, this statement is basically ignored

 

require

require 'include/init.inc.php';
  • Require will include the file - even if already included - as an overwrite.
  • Previous variable declarations and functions will be replaced.

 

require_once

require_once 'include/init.inc.php';
  • require_once will ONLY include the file if NOT already included.
  • if file already included, this statement is basically ignored
Tags