I'm trying to create an Autoloader class, so that I'll be able to load all modules automatically. But the problem is, I want to set a global from configuration file, and later, just call all of them by using:
Autoloader::GetGlobals();
So far, I have these 3 files:
Configuration.php
<?php
global $Configuration;
$Configuration['Globals'] = "Core Database Templates Directory Debugger";
?>
Autoloader.Class.php
<?php
require_once('Configuration.php');
private static $Globals = "";
private static $MakeGlobal = "global ";
public static function GetGlobals()
{
$ParsedGlobals = "";
$Globals2String = explode(" ", Autoloader::$Globals);
foreach($Globals2String as $Global)
$Globals[] = "$".$Global;
$DefinedGlobals = count($Globals);
for ($i = 0; $i < $DefinedGlobals; $i++)
{
$LastElement = $DefinedGlobals - 1;
if($i != $LastElement)
$ParsedGlobals .= $Globals[$i].", ";
else
$ParsedGlobals .= $Globals[$i].";";
}
return Autoloader::$MakeGlobal.$ParsedGlobals;
}
?>
I'm getting the right output:
global Core, Database, Templates, Directory, Debugger;
The next thing is that I want to interpret this as PHP code and not as a string, and I don't want to use eval() (because I've read many articles that says that this is the last function to be used).
So the question is, is it possible to run this string from return as PHP code by simply calling it as Autoloader::GetGlobals();?
evalis the last function to be used are trying to tell you its a bad idea to do what you're trying to do.$GLOBALSsuper global array right? If you really needed global access to the variables, you could just use that.