Help - Search - Members - Calendar
Full Version: Difference
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Anamika1
Hello,
Is anybody know the difference between require or include? rolleyes.gif
Ed
Basically require throws a Fatal error and exits the script's execution if the file to be 'required' is not present; where-as include just throws a warning and script execution continues.

It really depends on the context on which to use, though I can think of very few reasons you'd want a script to continue if you told it to include something and that file didn't exist.

From the manual:

QUOTE(http://php.net)
require() and include() 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, don't hesitate to 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. Be sure to have an appropriate include_path setting as well.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.