Monday, April 5, 2010

include() and require()

There are 2 functions that identical in every way, except how they handle errors:
  • include() - generates a warning, but the script will continue execution.
  • require() - generates a fatal error, and the script will stop.


include() Function

The example below shows a standard header file, called "header.php". To include the header file in a your page, use the include() function:


(click image to view)



require() Function

The example below shows an error using require() function:


(click image to view)

Error message:



The echo statement is not executed because the script stopped after the fatal error. I recommend you to use the require() function instead of include(), because script should not continue after an error.

No comments:

Post a Comment