What are common pitfalls when using require() in PHP scripts?

Common pitfalls when using require() in PHP scripts include not checking if the file exists before requiring it, leading to fatal errors if the file is missing. To avoid this issue, always use file_exists() function to check if the file exists before requiring it.

$file = 'myfile.php';

if (file_exists($file)) {
    require($file);
} else {
    echo "File does not exist.";
}