Difference between require() and include() in PHP (original) (raw)
Last Updated : 23 Jul, 2025
In this article, we will see the require() and include() Functions in PHP, along with understanding their basic implementation through the illustration. Both require() and include() Functions are utilized to add the external PHP files in the current PHP script. With this, both functions enhance the code reusability, along with breaking down large applications into smaller, more manageable parts.
**PHP require() Function
The require() function in PHP is basically used to include the contents/code/data of one PHP file to another PHP file. During this process, if there are any kind of errors then this require() function will pop up a warning along with a fatal error and it will immediately stop the execution of the script. In order to use this require() function, we will first need to create two PHP files. Using the require() function, include one PHP file into another one. After that, you will see two PHP files combined into one HTML file.
**Example 1: This example illustrates the basic implementation of the require() Function in PHP.
HTML `
Welcome to geeks for geeks!
Myself, Gaurav Gandal
Thank you
GFG.php
`
**Output:
**PHP include() Function
The include() function in PHP is basically used to include the contents/code/data of one PHP file to another PHP file. During this process if there are any kind of errors then this **include() function will pop up a warning but unlike the require() function, it will not stop the execution of the script rather the script will continue its process. In order to use this **include() function, we will first need to create two PHP files. Using the **include() function, include one PHP file into another one. After that, you will see two PHP files combined into one HTML file.
**Example 2: This example illustrates the basic implementation of the include() Function in PHP.
HTML `
Welcome to geeks for geeks!
Myself, Gaurav Gandal
<p>Thank you</p>
<?php include 'GFG.php'; ?>
GFG.php
`
**Output:
**Difference between require() and include() Functions:
| include() | require() |
|---|---|
| The **include() function does not stop the execution of the script even if any error occurs. | The **require() function will stop the execution of the script when an error occurs. |
| The include() functiondoes not give a fatal error. | The **require() function gives a fatal error |
| The **include() functionis mostly used when the file is not required and the application should continue to execute its process when the file is not found. | The **require() function is mostly used when the file is mandatory for the application. |
| The include() function will only produce a warning (E_WARNING) and the script will continue to execute. | The **require() will produce a fatal error (E_COMPILE_ERROR) along with the warning and the script will stop its execution. |
| The **include() function generate various functions and elements that are reused across many pages taking a longer time for the process completion. | The **require() function is more in recommendation and considered better whenever we need to stop the execution incase of availability of file, it also saves time avoiding unnecessary inclusions and generations. |