CodeIgniter Forums
Helper files - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived General Discussion (
+--- Thread: Helper files (/thread-29749.html)

Helper files - El Forum - 04-20-2010


I just thought about the fact that helper files doesn't use classes, why is that? Isn't the oop way of doing helpers to use static functions inside a class.

For example:

instead of:

// Dennis

Helper files - El Forum - 04-20-2010

Putting functions inside a class is good for separating them. You could have a math::rand function and also a sort::rand function, for instance.
But there is also a practical aspect to consider. It would be annoying to have to use every helper function in your view prefixed by its class.
I think the current situation is a good inbetween.

Helper files - El Forum - 04-21-2010

If you ask me its more logical to use static functions instead of normal functions, just like you said rand could be for example math -> rand or sort -> rand.

But if I don't use static functions and if I didn't write all of the app I wouldn't know if the function rand is for sorting or for math, if it was static I would be able to call Sort:: and get available helper functions for sorting.

But after all PHP is built in the same way as the helper functions in CI, if you want a random number you call rand() and not Math::rand().