well another reason is because i'm trying to limit the amount of globals within the system and limit them to under 10 hoenstly. yes, the whole system is in classes and i know the hit i'm going to take but the nice and neat code makes me soooooo happy you don't even know.
ok, my loader class as it stands consists of just 1 function and 1 variable. i planned to make it more but this is where i need help.
this is the loader class
Code: Select all
<?php
//[b]loader.php[/b]
class Loader
{
var $cached_vars = array();
function load($name)
{
global $load;
$this->object = new $name();
}
}
?>now in the index.php i have this:
Code: Select all
//[b]index.php[/b]
include 'class.php';
include 'loader.php';
$load;
$CI;
$loader = new Loader();
$loader->load("everything");
$loader->object->thing();Code: Select all
//[b]class.php[/b]
class everything
{
function thing() { echo 'thing'; }
}now. this works like a charm. the problem is (so i think) is that php loads everything up right at runtime. and i do not want it to add all the files to memory that doesn't need to be there. i'm trying to be conservative here with my code (C background
so, if i have both those includes it'll load them up and it's easy for it to know where to get the class names. which is awesome but also not so much at the same time IMO. i want to have functions in there that are specific for certain things. such as load the database object, or load a PHP tool or load the user information. you understand? i planned to work the whole system like this so i could also limit my include statements as well.
any ideas?
example load function
Code: Select all
function loadDatabaseObject()
{
// check which type of DB we are running. from the config file
// goto the folder where the DB files are stored
// inlucde those files
}
function unloadDatabaseObject()
{
// unload whatever object we have in the class array variable.
}