且构网

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

require、include、require_once 和 include_once 之间的区别?

更新时间:2023-11-17 12:44:10

还有requireinclude_once.

所以你的问题应该是...

So your question should be...

  1. 我应该什么时候使用 requireinclude?
  2. 我应该什么时候使用 require_oncerequire
  1. When should I use require vs. include?
  2. When should I use require_once vs. require

此处描述了 1 的答案.

require() 函数与 include() 相同,只是它处理错误的方式不同.如果发生错误,include() 函数会生成警告,但脚本将继续执行.require() 产生致命错误,脚本将停止.

The require() function is identical to include(), except that it handles errors differently. If an error occurs, the include() function generates a warning, but the script will continue execution. The require() generates a fatal error, and the script will stop.

可以在此处找到 2 的答案.

The answer to 2 can be found here.

require_once() 语句与 require() 相同,除了 PHP 会检查文件是否已经被包含,如果是,则不再包含(要求)它.

The require_once() statement is identical to require() except PHP will check if the file has already been included, and if so, not include (require) it again.