Difference between include()and require() in PHP | include() vs. require()
In previous post, we have seen how to include files in PHP using include(), require, include_once() and require_once().
All these function helps you to include/insert content of one file to another file. Both have same functionality but have differences too. Lets see the difference between include() and require() function.
Difference between include() and require() in PHP :
|include() function takes one argument , a path/name of the specified file you want to include.||require() function performs the similar functionality as include() function, takes one argument i.e. path/name of the file you want to include.|
|include() function does not stop execution , just give warning and continues to execute the script in case of file name not found i..e missing/misnamed files .||require() function gives fatal error if it founds any problem like file not found or misnamed files and stops the execution once get fatal error.|
|include() function can be used in loops or control structure.||require() function can not be used in loops or control structures.|
|You can return a value from an included file
$result = include ‘rtnvalue.php’;
|File included as the result of a require statement cannot return a value.|
|You can use include when file is not required or not so important .||When file is required by the script, better to use require() instead of include().|