The include statement includes and evaluates the specified file.the following example of include we try to make two file one file content user information and second is display user data using include.
<?php
$fname = 'Bharat';
$lname = 'Makwana';
?>
<?php
include 'info.php';
echo "Welcome Mr"." ".$fname." ".$lname;
?>
Welcome Mr. Bharat Makwana
Require is a same work as includes and evaluates the specified file.but require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include only emits a warning (E_WARNING) which allows the script to continue.
<?php
require 'info.php';
echo "Welcome Mr"." ".$fname." ".$lname;
?>
The above example info.php are not available here but used require this script stop execution of this script.
Sr.No |
Include |
Require |
---|---|---|
1 |
include will attempt to load the specified file, but will allow the script to continue if not successfully loaded. |
require on the other hand will cause a "Fatal Error" to occur if the specified file is not successfully loaded. |
2 |
include produces a Warning if the file cannot be loaded. (Execution continues) |
require will throw a PHP Fatal Error if the file cannot be loaded. (Execution stops) |