For what condition should we use include and for what condition should we use require? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

For what condition should we use include and for what condition should we use require?

who is better for what condition

22nd Aug 2016, 8:22 PM
Hein Thiha
Hein Thiha - avatar
2 Answers
+ 3
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. Use require when the file is required by the application. Use include when the file is not required and application should continue when file is not found.
22nd Aug 2016, 10:03 PM
Alexandre Wavelet
Alexandre Wavelet - avatar
+ 2
Include is used every time you only include a file. Require is used whenever a file necessarily need another file to work. That is, without the required file in question the script not work.
22nd Aug 2016, 10:08 PM
Dimitri Marchetti
Dimitri Marchetti - avatar