<html>
<body>
<p>BEFORE</p>
<?php include("file_no_exist.txt");?>
<p>AFTER</p>
</body>
</html>
The output will be:
BEFORE
AFTER
But if we replace include with require the output would just be:
BEFORE
When the require statement cannot find the file it throws a fatal error which halts execution of the script; nothing after the require statement will be executed. For this reason it is generally considered best practice to use require over include because scripts should not be executing if necessary files are missing or misnamed.
No comments:
Post a Comment