About include and require in PHP

My computer develop environment

$ php -v
PHP 7.0.26

Difference between “include” and “require”

Different ways to deal with failure:

require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words,
it will halt the script whereas include only emits a warning (E_WARNING) which allows the script to continue.


  1. It will produce a fatal level error and halt the script
  2. File is just processed only once which is be included, because the file ‘s content will be replaced into the script.
  3. Conditional include function

Somebody think the ‘a.php’ will be include whether $some is true or not.

if ($come) { 
require 'a.php';

But i have try this is not work


  1. It Just emits a warning then it will allow the script to continue.
  2. File will be read and processed each time when file is been included.
  3. Unconditional include function

Difference between “include / require” and “include_once / require_once”

“_once” suffix means that file will not be loaded again if it is loaded


Thank you for reading.
This post is copyrighted by Liyuliang’s Blog.
If reproduced, please indicate the source: Liyuliang’s Blog
This blog uses Creative Commons Attribution-NonCommercial-Share-Sharing 4.0 International License Agreement to license.

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now