I wrote a tiny function called load, to include multiple file at once, instead of using multiple include statements. Things work fine, except when I echo a variable, I keep getting the Undefined variable
error.
Here are the files. The file that runs everything is inc-main.php
. That's where the Undefined variable
error is thrown on line 9
.
Any help on this can be solved? I don't get any file include errors which means the file are being included. The only problem is with the Variables.
load.php
<?php
$paths = array(
'iNa'=>ROOT.'/test/inc-a.php',
'iNb'=>ROOT.'/test/inc-b.php',
);
function load($files) {
global $paths;
$files = func_get_args();
foreach($files as $file) {
echo ($paths[$file]).'<br>';
require_once($paths[$file]);
}
}
?>
inc-a.php
<?php
$name = 'Donald';
$city = 'Duckberg';
?>
inc-b.php
<?php
$location = 'San Francisco';
?>
inc-main.php
<?php
define('ROOT',$_SERVER['DOCUMENT_ROOT']);
include(ROOT.'/test/load.php');
load('iNa','iNb');
echo 'Hello, my name is '.$name.', and I live in '.$city.'!'; /* Line 9 */
?>