How can one ensure proper variable scope when including files in PHP?

When including files in PHP, it's important to ensure proper variable scope by using functions or classes to encapsulate variables and prevent conflicts with other included files. One way to do this is to define variables within a function or class and then call that function or class when including the file.

// file1.php
function includeFile() {
    $variable = "Hello from included file!";
    return $variable;
}

// file2.php
include 'file1.php';
echo includeFile();