且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

include,include_once,require或require_once?

更新时间:2023-11-17 12:26:52

两者之间的唯一区别是需要及其姐妹 require_once 如果找不到文件则抛出致命错误,而包括 include_once 仅显示警告并继续加载页面的其余部分。如果您不希望PHP在没有数据库信息的情况下尝试加载页面的其余部分(我假设),则使用 require_once 。您不需要多次包含该文件,因此无需使用常规的 require 函数。

The only difference between the two is that require and its sister require_once throw a fatal error if the file is not found, whereas include and include_once only show a warning and continue to load the rest of the page. If you don't want PHP to attempt to load the rest of your page without the database info (which I would assume), then use require_once. You don't need to include the file more than once, so there is no need to use the regular require function.