Using a variable to dynamically load a class

PaulHuisinga

New Member
I have decided to use the singleton pattern for my application. It makes the most sense to me. However, just when I feel like I have made some progress I run into another wall.I have a load function. The load function does the following.Check if class has been previously loaded. - If so - return $class::get_instance();- Otherwise - look for class in various places - if found - return $class::get_instance(); - else return error.Before adopting the Singleton pattern I was instantiating classes with the load class.In the controller I would have this.\[code\]$session = $this->load->library('session');\[/code\]The load class would then find the file and return..\[code\]return new $class_name;\[/code\]I hoped that the in changing the method of loading classes it would be a tweak to a few lines but these tweaks are generating syntax errors.\[code\]return $class_name::get_instance();\[/code\]Is there a way to write the line above without the syntax error?
 
Back
Top