Just like the previous lesson, the require command is used to include a file into your PHP code. However there is one huge difference between the two commands.
When you include a file with the include command and PHP cannot find it you will see an error message like the following:PHP Code:
<?php include("noFileExistsHere.php"); echo "Hello World!"; ?>
Notice that our echo statement is still executed, this is because a Warning does not prevent our PHP script from running. On the other hand, if we did the same example but used the require statement we would get something like the following example.PHP Code:
<?php require("noFileExistsHere.php"); echo "Hello World!"; ?>
The echo statement was not executed because our script execution died after the require command returned a fatal error! We recommend that you use require instead of include because your scripts should not be executing if necessary files are missing or misnamed.