What is the difference between include and required_once()? I want to include another php file let us consider as sample2.php in example1.php.Which is the best practice to use.
Asked
Active
Viewed 312 times
-2
-
`_once` functions make sure that the file being called is only loaded one time, if that file happens to be included in another file that also needs it and is included in the first it won't load it again it'll just use the one it loaded previously. – m.e.conroy Oct 22 '13 at 13:18
1 Answers
0
To put it in the simplest terms, your PHP page can still run with an include
file not being retrieved, where as if it's a required_once
and the file it's trying to get doesn't exist or is not in the right directory, the whole page will fail to load
There are more of these:
require_once
require
include
include_once
The once
ones will only include the file once in the page if multiple times it is called, whereas the functions without once
will call them as many times as they are in your code.

Albzi
- 15,431
- 6
- 46
- 63