What are the potential pitfalls of including variables in PHP files using the include function?

Potential pitfalls of including variables in PHP files using the include function include variable scope issues and potential security vulnerabilities if the included file is not properly sanitized. To solve this issue, it is recommended to use the `require` or `require_once` functions instead of `include` to include files that contain variables, as they will throw a fatal error if the file cannot be included. Additionally, it is important to properly sanitize any variables included in external files to prevent security vulnerabilities.

<?php
// Include file with variables using require_once
require_once 'variables.php';

// Sanitize variables before using them
$var = htmlspecialchars($var);
?>