Skip to content
Advertisement

Difference between “include” and “require” in php

Is there any difference between them? Is using them a matter of preference? Does using one over the other produce any advantages? Which is better for security?

Advertisement

Answer

You find the differences explained in the detailed PHP manual on the page of require:

require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include only emits a warning (E_WARNING) which allows the script to continue.

See @efritz’s answer for an example

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement