- get_defined_vars: documentation ( source)
- extract: documentation ( source)
- is_file: documentation ( source)
<?php
// overly simplified example
function test1()
{
$a = 3;
test2();
}
function test2()
{
echo $a;
}
// the actual idea is to do something like this
// main.php
$vars = [];
function load_file($path)
{
if(is_file($path))
{
$GLOBALS['path'] = $path;
load_isolated();
}
}
function load_isolated()
{
extract($GLOBALS['vars']);
require($GLOBALS['path']);
$GLOBALS['vars'] = get_defined_vars();
}
load_file('a.php');
// a.php
$a = 3;
load_file('b.php');
//b.php
echo $a; // warning or error that var $a doesn't exist because get_defined_vars() was never called yata yata