What are common pitfalls when using include statements in PHP, and how can they lead to undefined variable errors?

Common pitfalls when using include statements in PHP include not checking if the included file exists before including it, leading to undefined variable errors if the included file relies on variables defined in the parent file. To avoid this issue, always check if the file exists before including it and ensure that any necessary variables are defined before including the file.

if (file_exists('included_file.php')) {
    include 'included_file.php';
} else {
    echo 'File not found.';
}

// Define any necessary variables before including the file
$variable = 'value';
include 'included_file.php';