开发者

include or required

开发者 https://www.devze.com 2022-12-24 21:53 出处:网络
What should I use in the following statement? Include or required. if(a ==b){ require \'requiredfile.php\';

What should I use in the following statement? Include or required.

if(a ==b){
 require 'requiredfile.php';
} else {
 require 'requiredfile_2.php'
}

If in a function, I know that one, either include or require, only includes the file when call开发者_如何学Ced, the other one will include the file regardless. Am I correct?


The difference between include and require is that include will only emit a warning when the file is not found, and require will terminate with a fatal error.

If you are loading vital program parts, you probably want to go with require.

Manual

require() is identical to include() except upon failure it will also produce a fatal E_ERROR level error. In other words, it will halt the script whereas include() only emits a warning (E_WARNING) which allows the script to continue.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号