What is the difference between include, require, include_once, and require_once in terms of execution flow?

Last updated 15 June 2026

All four pull in another file at runtime, but they differ in two axes: how they react to a missing/failed file (include vs require) and whether the file is loaded more than once (the _once variants).

  • Failure behavior:

    • include: on failure emits an E_WARNING and the script continues executing.

    • require: on failure emits an E_COMPILE_ERROR (fatal) and halts the script.

  • The _once variants add deduplication:

    • include_once / require_once track already-included paths and skip a second load.

    • This prevents redeclaration errors (functions, classes) and re-running top-level code.

  • Rule of thumb:

    • Use require (or require_once) for files the app cannot run without (bootstrap, class definitions).

    • Use include only when the file is optional and a missing one shouldn't kill execution.

  • In practice, modern code uses an autoloader (Composer/PSR-4), so manual require_once is mostly limited to the bootstrap file.

  • https://www.php.net/manual/en/function.include.php
  • https://bugs.php.net/35176
  • https://medium.com/@404_namenotfound/whats-the-difference-between-include-include-once-require-and-require-once-in-php-9b414c983967
  • https://www.deviantdev.com/journal/php-difference-include-require-once
  • https://anandbaraik.hashnode.dev/what-is-the-difference-between-include-and-require-in-php
  • https://www.youtube.com/watch?v=d6InA-6F5iw
  • https://www.php.net/manual/en/function.include-once.php
  • https://www.php.net/manual/en/function.require-once.php
All PHP interview questions