What are common pitfalls when using include and require in PHP?

Common pitfalls when using include and require in PHP include using the wrong file path, causing errors in the script execution. To avoid this, always use absolute paths or relative paths correctly. Another common pitfall is including the same file multiple times, which can lead to redeclaration errors. To prevent this, use include_once or require_once instead.

// Using absolute path
include '/path/to/file.php';

// Using relative path
include 'folder/file.php';

// Using include_once to prevent redeclaration
include_once 'file.php';