What is the difference between include_once and require_once?
Why Interviewers Ask This
Mid-level PHP roles require deep understanding of this topic. Interviewers ask this to separate candidates who truly understand the mechanics from those who only know surface-level concepts.
Answer
Both include_once and require_once include a file only once — if the file has already been included, PHP skips including it again (preventing function/class redeclaration errors). The only difference is what happens when the file cannot be found: include_once generates a warning (E_WARNING) and continues script execution. require_once generates a fatal error (E_COMPILE_ERROR) and halts execution. Use require_once for files that the application cannot function without (autoloaders, configuration files, base classes). In modern PHP with Composer autoloading, you rarely need to call these manually — the autoloader handles file inclusion automatically.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last PHP project, I used this when...' immediately makes your answer more credible and memorable.