I would like to use vaiables defined in another php file in a included file in a function.
I have something like this:
/* INDEX.PHP */
require('main.php');
require('utils.php');
$error = ([condition]);
if ($error) {
    error_404();
}
require('page.php'); //The normal content of the page, replaced by error404.php in case of error
/* UTILS.PHP */
function error_404() {
    header('HTTP/1.0 404 Not Found');
    include('error404.php'); //This file needs the 'main.php' required outside the function.
    exit();
}
The error404.php file included in the error_404() function needs to use the functions and variables declared in the main.php file included outside the function.
I need something like "move the include main.php to the function environment". Does anyone know how can I solve this problem?.
 
    