Welcome Guest, Not a member yet? Register   Sign In
load->library() doesn't support singletons!

I'm implementing a few classes in the CodeIgniter "libraries" folder as singletons in the following manner:

public static function getInstance() {.....}

private function __construct() {}

CodeIgniter's load->library(), however, always expects a public constructor.

Is it possible to implement and load CI library classes as singletons?

Also, what was the logic behind forcing lower case names of variables returned by load->library()?

In general, the CodeIgniter's library loading functionality leaves much to be desired.

This should work, you can load the library without run it, and then use your static methods as always

$this->load->library('yourclass', false);


Hi Alex,

Your idea didn't work. CodeIgniter still complains about trying to call a private constructor.

I found a way to substitue CodeIgniter's anemic load->library() function with standard PHP class loading.

In the root index.php, I added the following line:

Inside a controller, I access my class the regular PHP way:

require_once myclass;


Ok I wasnt going to get into this thread because I did not want what I said appear to be negative.
So please do not take it that way....

What you are trying to do is just not the way CI works. It does use a public constructor so you should just do the same.
I know you want to use PHP 5 etc but since CI is PHP 4 compatible it is better, in my opinion only, to just work with it the way you have to and move on.

Sorry @sherbo, i was talking about load_class function not loader class, my fault. I use this function to load static classes without problem.

Theme © iAndrew 2016 - Forum software by © MyBB