Explain the difference between include, require, include_once, and require_once.

Beginner

Answer

  • include: Includes a file; produces a warning if file not found but continues execution
  • require: Includes a file; produces a fatal error if file not found and stops execution
  • include_once: Same as include but ensures the file is included only once
  • require_once: Same as require but ensures the file is included only once

The "_once" variants prevent redeclaration errors when the same file might be included multiple times.