PHP require function

The require function introduction

The require function almost works similar to PHP include except, the way an error is handled. If there is some problem in loading the included file by using the require function e.g. given path is incorrect or accidentally misspelled the file name then require function will generate a Fatal Error. Whereas the same problem in include function will generate just a warning error message.

The code of file name referred in the calling PHP file will be copied there before execution in PHP require function.

Syntax of  require function


Example of using require

The require file path

If you have an include folder, for example, then the above example would look like this

So left_nav.php and footer.php files are placed inside the include folder (for above example) while calling PHP file is beside or outside of the include folder.

Was this article helpful?

Related Articles

Leave A Comment?