The require() function is identical to include(), except that it handles errors differently.
The include() function generates a warning (but the script will continue execution) while the require() function generates a fatal error (and the script execution will stop after the error).
 
Example with the require() function.
PHP code:
<html>
<body>
 
<?php
require("wrongFile.php");
 echo "Hello World!";
?>
 </body>
</html>
Error message:
Warning: require(wrongFile.php) [function.require]:
 failed to open stream:
No such file or directory in C:\home\website\test.php on line 5
 
Fatal error: require() [function.require]:
Failed opening required 'wrongFile.php'
 (include_path='.;C:\php5\pear')
in C:\home\website\test.php on line 5 
No comments:
Post a Comment