What are common pitfalls when including files in PHP projects?

Common pitfalls when including files in PHP projects include using relative paths that may break when the project structure changes, not handling errors when including files that do not exist, and including files multiple times which can lead to conflicts or errors. To avoid these pitfalls, it is recommended to use absolute paths or utilize PHP's magic constants like __DIR__ to ensure consistent file inclusions, check if the file exists before including it, and use include_once or require_once to prevent duplicate inclusions.

// Example of including a file using absolute path and handling errors
$file = '/path/to/file.php';
if (file_exists($file)) {
    include $file;
} else {
    echo 'File not found';
}