include和require的区别

require()函数是指包含进来的内容被当成当前文件的一个组成部分,所以当包含进来的文件有语法错误或者文件不存在的时候,那当前文件的PHP脚本都不再执行。

include()函数相当于指定这个文件的路径,当被包含的文件有错时,不会影响到本身的程序运行。

首先在includerequire 这二个字面意思去体会!include 是包含,require 是需要

很容易就是看出强调的语气不一样! require 出错汇报error 后面的程序不在执行!
include 出错则报waring !后面的程序继续执行!

当然还有他们的衍生:include_once() require_once();

php官方的 php手册上的解释

require 和 include
几乎完全一样,除了处理失败的方式不同之外。require
在出错时产生 E_COMPILE_ERROR
级别的错误。换句话说将导致脚本中止而 include
只产生警告(E_WARNING),脚本会继续运行。

官方解释:
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
原文地址:https://www.cnblogs.com/webzhuo/p/4226366.html