PHP: include & require, what is different?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
montyauto
Forum Commoner
Posts: 25
Joined: Sat Jan 13, 2007 7:05 am

PHP: include & require, what is different?

Post 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.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply