Explain include(), include_once, require() and require_once?

Explain include(), include_once, require() and require_once?

Include(), include_once, require() and require_once are different functions that often used in PHP coding. 

  • include(): The include() function is used to insert a php file into the current php file. In execution, if an error occurs, the include() function gives a warning and the script still gets executed.
  • include_once(): The include_once() function inserts the php file into the current php file only once. The php file will be called only once and any more calling of that file will be ignored.
  • require(): Require() function is similar to include() function. Only difference is that, if an error occurs in execution, it treats it as a fatal error and the script stops execution.
  • require_once(): The require_once() includes the php file into the current php file only once.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.