+ 6

require_once(), require(), include().What is difference between them?

(PHP)

14th May 2019, 12:31 PM
Yeabsira Mekuria
Yeabsira Mekuria - avatar
5 Answers
+ 6
All functions can be used to include a php file in another one. The use of Require will generate an error if the file not found while Include() doesn't . Require_once() If it is found that the file has already been included, calling script is going to ignore further inclusions.
14th May 2019, 12:52 PM
Mia380
Mia380 - avatar
+ 6
You know the answer already to provide it yourself.
14th May 2019, 11:52 PM
Sonic
Sonic - avatar
+ 5
require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don’t include the file more times and you will not get the “function re- declared” error.
14th May 2019, 4:36 PM
Yeabsira Mekuria
Yeabsira Mekuria - avatar
+ 3
But u r not quite right.....
14th May 2019, 2:40 PM
Yeabsira Mekuria
Yeabsira Mekuria - avatar
+ 2
required():when use this function while if file is not found then its give to error so it is required for code. required_once():If we call one file two or more times then its call only once so,this is ignore other calls for same files. include(): If file is present then its included in to code or not then not generate error.So when file's code is not important for code while we can use this function.
15th May 2019, 8:19 AM
Nirali Vachhani
Nirali Vachhani - avatar