CodeIgniter Forums

Full Version: Helper files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Dennis_gull[/eluser]
Hi,

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:
math::rand(x)

instead of:
rand(x);

// Dennis

El Forum

[eluser]mddd[/eluser]
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.

El Forum

[eluser]Dennis_gull[/eluser]
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().