PHP Programing language

adplus-dvertising
PHP Require
Previous Home Next

The PHP in using a require command it's using to include a file into your PHP code. In PHP there is one huge difference between the two commands, though it might not seem that big of a deal.

Require Vs Include:

We can include a file with the include command and PHP cannot find it you will see an error message like the following:

<?php
include ("This file is not here.php");
echo "r4rtechsoft!";
?>

Output

r4rtechsoft!

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
include ("This file is not here.php");
echo "r4rtechsoft!";
?>

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.

Previous Home Next