What best practices should be followed when including or requiring files in PHP to avoid syntax errors?
When including or requiring files in PHP, it is important to use the correct file paths and include proper error handling to prevent syntax errors. It is recommended to use the absolute file paths or the `__DIR__` constant to ensure the correct file is included. Additionally, always check if the file exists before including it to avoid any potential issues.
// Using absolute file path
require_once '/path/to/file.php';
// Using __DIR__ constant
require_once __DIR__ . '/file.php';
// Check if file exists before including
if (file_exists('file.php')) {
require_once 'file.php';
} else {
echo 'File not found';
}