Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

php - require,include,require_once和include_once之间的区别?(Difference between require, include, require_once and include_once?)

In PHP:

(在PHP中:)

  • When should I use require vs. include ?

    (什么时候应该使用requireinclude ?)

  • When should I use require_once vs. include_once ?

    (什么时候应该使用require_onceinclude_once ?)

  ask by Scott B translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are require and include_once as well.

(还有requireinclude_once 。)

So your question should be...

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

  1. When should I use require vs. include ?

    (什么时候应该使用requireinclude ?)

  2. When should I use require_once vs. require

    (我何时应该使用require_oncerequire)

The answer to 1 is described here .

(这里描述1的答案。)

The require() function is identical to include(), except that it handles errors differently.

(require()函数与include()相同,除了它对错误的处理方式不同。)

If an error occurs, the include() function generates a warning, but the script will continue execution.

(如果发生错误,include()函数将生成警告,但脚本将继续执行。)

The require() generates a fatal error, and the script will stop.

(require()产生致命错误,脚本将停止。)

The answer to 2 can be found here .

(在这里可以找到2的答案。)

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.

(require_once()语句与require()相同,除了PHP会检查文件是否已包含,如果不包含,则不要再次包含(require)该文件。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...