Welcome Guest, Not a member yet? Register   Sign In
Idea: Semi-Auto-Loading of Libraries, worth it or useless?
#1

[eluser]nizsmo[/eluser]
Hi All

Recently I have been thinking of exploring and adding a (actually quite small/simple, but neat) feature to codeigniter.

Don't you hate it when you encounter errors like:
"Fatal error: Call to a member function {function_name}() on a non-object in \path\to\your\website\code\file\here\file.php on line 26"?

I normally encounter this message while I want to use a library, but the library has not been auto-loaded and I forgot to load it beforehand.
So I was thinking, what if I implemented a special function to load the library semi-automatically? I say semi-automatically because it will only load the library when the library hasn't already been loaded, and ONLY when you need it.

So to summarize, the positives:
- Less code, don't have to write $this->load->library('your_lib'); every time you want to use the library
- if you forget to load a library, the library will still be loaded and it won't kill your whole site with a fatal error
- more efficient than autoloading, since it only loads the library when you need it, so theoretically, you will not have to auto-load anything at all.

the down-side:
- this will only work for libraries, and not for helpers, etc... (which are individual functions)
- because it will only work for libraries, it may confuse people because of the added different way to load libraries, which are not applicable to helpers etc... (I guess I am worried about uniformality?)

Any thoughts anyone?
Suggestions and comments welcome!

Many thanks! Smile
#2

[eluser]nizsmo[/eluser]
I just added a poll, just wanted to see what the general opinion towards this idea would be. Hope you guys can give a vote or 2, better yet some feedback.

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB