include or required
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.
精彩评论