PHP Include versus Require

PHP allows several ways to include other PHP files: Include, Include Once, Require, and Require Once. The difference between Include and Require is whether or not to halt script execution. Appending Once simply checks if the file has been required or included previously.

Include

The include() statement includes and evaluates the specified file.

Include Once

The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. As the name suggests, it will be included just once.

Require

require() and include() are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, don’t hesitate to use require() if you want a missing file to halt processing of the page.

Require Once

The require_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the require() statement, with the only difference being that if the code from a file has already been included, it will not be included again.

Tags: ,

Comments are closed.

Search

Websites

  • slide
  • slide
  • slide
  • slide