Page 1 of 1

PHP: include & require, what is different?

Posted: Tue Jun 12, 2007 10:39 am
by montyauto
Hope this is not stupid question.

I read the manual frequently, still could not understand what different between include() and require(), it makes no different to me.

Could you show me in an example script to show the different result between those two? Thanks.

Posted: Tue Jun 12, 2007 11:17 am
by AKA Panama Jack
With INCLUDE if the file isn't found a Warning is issued and the script will continute to try and execute.

With REQUIRE if the file isn't found a Fatal Error is generated and the script immediately stops executing.

Posted: Tue Jun 12, 2007 11:32 am
by RobertGonzalez
The PHP Manual page for include() wrote:The documentation below also applies to require(). The two constructs are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless.