i was bitten by some ABSTRACTION & ORGANISATION bug and i decided that i would include files in my php application by using a class called Loader which looks like this
class Loader
{
public $loadedFiles=array();
public function isLoaded($fileName)
{
if(in_array($fileName,$this->loadedFiles))
return true;
else
return false;
}
public function load()
{
$fileList=func_get_args();
foreach ($fileList as $file)
{
if(!$this->isLoaded($file))
{
$flag=include(ROOT_DIR_PATH.'includes'.DS.$file);
if($flag)
{
$this->loadedFiles[]=$file;
}
else
return false;
}
}
}
}
Now i can include files in my app using something like this
$loader=new Loader();
$loader->load('db.class.php','utility.php','objects.php');
but the problem is that now all the functions of the files included by the above method are granted the scope of the above method load. now i cant use any functions of the included files . Whenever i use any function of the above included files i get a warning saying undefined function. Is there some way i can grant global scope to the functions of the included files.
Looks like the problem is somewhere else. I have tried to simulate what you were trying to do and it worked for me.
include1.php
include2.php
And the result was this: This is tester
There wasn’t any scoping issue. As @JackTurky mentioned, check the path.