Welcome Guest, Not a member yet? Register   Sign In
Where to put standard functions that reference lib/mod methods
#3

A helper would be the best practice in this case. The helper functions should load the library as needed via
Code:
get_instance()->load->library('YourLibrary');

The only advantage to putting the helper functions at the end of the library's file is that it's somewhat safer to assume the library has already been loaded and the end user doesn't have to load the helper if they've already loaded the library.

Personally, I would prefer not to have helper functions loaded every time I load a library. Bonfire has a few libraries that do this, and I've been considering adding some configuration options to make it possible to separate the libraries from their helpers while maintaining backwards compatibility. Once you get to that point, though, the formula for weighing the advantages against the disadvantages is pointless, because the cost of checking for an additional config value and choosing not to load a helper file is probably pretty close to the cost of loading a small number of extra functions after the end of the class declaration in the library, except, of course, for the general costs associated with declaring global functions in the first place.
Reply


Messages In This Thread
RE: Where to put standard functions that reference lib/mod methods - by mwhitney - 08-11-2015, 06:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB