require 与 include区别?
require 这个函数通常放在PHP程序最前面 。
PHP程序在执行前,就会先将require指定的文件读取,使它成为PHP程序的一部分。常用这个函数引入PHP文件。
include 这个函数一般使用在流程控制的时候使用。可以先判断是否需要读取指定文件,再决定是否读取文件。执行的时候才读取。
一下为补充
1.include有返回值,而require没有
2.require 和 include 对于错误
require存在错误的时候,那么程序就会中断执行了。并显示错误
include存在错误的时候,那么程序不会中断,而是继续执行,并显示一个错误
3.require 和include的变量
两者变量的调用理念是相同的。那么就是必须事先就存在的变量才能调用。但是include可能会由于变量未及时引入导致变量并不存在
4.require是无条件包含,也就是如果在一个流程控制里面加入require,无论条件成立否都会引用require指定的文件。因为PHP程序在未执行的时候已经引入了。
5.require和include的使用
require 一般放在PHP文件的头部。来引入那些必须引入的文件。
include则放在流程控制的语句中更适合。