Search code examples
phprequire-once

require_once - does it load the whole script?


Just wondering if require_once (or any of the include type functions) loads the entire external script when you call it, or just the functions from that script as you call them from the script you are using require_once in?


Solution

  • It loads the entire script. The only difference between require and require_once is that if you call require_once multiple times with the same script argument, the repetitions will be ignored.

    A script loaded with require or include can have other things besides function definitions, and they need to be executed immediately when the file is loaded.