+ 2
Include in PHP
Are there any advantages using 'include' instead of 'require'? As I see it, one should always use 'require' since it will produce a fatal error and stop the script if the file is not found.
2 Respostas
+ 16
The only advantage of include is that it does not break the whole page if an included file isn't found.
+ 1
<?php
try {
$path = "Idon'tKnowIfItExists.php";
if ( ! file_exists($path)) {
throw new Exception('File does not exist');
}
include $path;
} catch (Exception $e) {
header("Location: /?page=404");
}
?>
https://code.sololearn.com/wGJO5GANO3hA/?ref=app