well what im trying to do is build a classes constructor that has a variable amount of required parameters that are need to construct the object.
the problem is in the classname() function this class is suppose to make an object of the class and then return that object for use.
<?php if(!defined('MASH')){exit('No Direct Access Allowed');}
class Loader
{
private $loaded = array();
private static $init;
private function __construct(){}
public static function Init()
{
if(!(self::$init instanceof self))
{
return self::$init = new self;
}
return(false);
}
public static function Mash_Autoload($classname)
{
if(!class_exists(ucfirst(strtolower($classname)) , FALSE) && !is_object($classname))
{
if(file_exists(MASH_LIB_PATH . ucfirst(strtolower($classname)) . EXT))
{
require(MASH_LIB_PATH . ucfirst(strtolower($classname)) . EXT);
}
elseif(file_exists(MASH_APP_PATH . ucfirst(strtolower($classname)) . EXT))
{
require(MASH_APP_PATH . ucfirst(strtolower($classname)) . EXT);
}
elseif(file_exists(MASH_CONTROLLER_PATH . ucfirst(strtolower($classname)) . EXT))
{
require(MASH_CONTROLLER_PATH . ucfirst(strtolower($classname)) . EXT);
}
elseif(file_exists(MASH_MODELS_PATH . ucfirst(strtolower($classname)) . EXT))
{
require(MASH_CONTROLLER_PATH . ucfirst(strtolower($classname)) . EXT);
}
elseif(file_exists(MASH_MODULES_PATH . ucfirst(strtolower($classname)) . EXT))
{
require(MASH_MODULES_PATH . ucfirst(strtolower($classname)) . EXT);
}
elseif(file_exists(MASH_EXT_PATH . ucfirst(strtolower($classname)) . EXT))
{
require(MASH_EXT_PATH . ucfirst(strtolower($classname)) . EXT);
}
elseif(file_exists(MASH_CORE_PATH . ucfirst(strtolower($classname)) . EXT))
{
require(MASH_CORE_PATH . ucfirst(strtolower($classname)) . EXT);
}
else
{
require(MASH_LIB_PATH . 'Exceptions' . EXT);
throw new Mash_Autoload_Exception('Fatal Error:' . $classname . 'Could Not Be Located');
}
}
}
public function Classname($classname , array $params = array())
{
static $__instance;
if(!isset(self::$init->loaded[$classname]))
{
if(!class_exists($classname , FALSE) && ! is_object($classname))
{
$classname = new $classname;
if(method_exists($classname , '__construct'))
{
call_user_func_array(array($classname , '__construct') , $params);
if(is_object($classname))
{
return $classname;
}
else
{
require(MASH_LIB_PATH . 'Exceptions' . EXT);
throw new Mash_Loader_Exception("$classname Could Not Be Converted to Object");
}
}
else
{
return $classname;
}
}
else
{
require(MASH_LIB_PATH . 'Exceptions' . EXT);
throw new Mash_Loader_Exception('Fatal Error:'. $classname . 'Already Exists');
}
}
}
}