CodeIgniter Forums
Scope library methods vs helper functions and other related questions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Scope library methods vs helper functions and other related questions (/showthread.php?tid=3829)



Scope library methods vs helper functions and other related questions - El Forum - 10-24-2007

[eluser]xwero[/eluser]
I've been wondering about this for a while. Is it right the scope of library methods and helper functions are the same? Is there a difference performance wise?

According to me the idea is that helpers are library independent, right?

I'm trying to understand the finer details of CI.


Scope library methods vs helper functions and other related questions - El Forum - 10-24-2007

[eluser]Phil Sturgeon[/eluser]
Its a tricky one as you could easily use either. I often start off writing a helper file then convert it to a library as it grows.

I preffer to use a library for a series of functions that are often used in sequence or use shared data between them (i.e if it needs to return more than one value, or you are passing it lots of params to each function).

An important thing to remember is with libraries you get flexibilty. With the library name you get namespaces, emaning you dont have to worry what they are called as it wont be redefining an existing function in another helper.

I can see there being much of a performance hit. The tiniest bit slower as its loading a class instead of a page full of functions but... I really cant see it making any noticeable difference no matter how many people are blasting away on your site.


Scope library methods vs helper functions and other related questions - El Forum - 10-24-2007

[eluser]xwero[/eluser]
Thank you for your explanation.

Most of the time i go the library way because the functions are library dependent, if i use them in different libraries i abstract them to be more generic and put them in a helper file.

You are right about namespacing. I like the way it enables you to name a method/function properly instead of coming up with some name you haven't used yet.