Welcome Guest, Not a member yet? Register   Sign In
Helper files


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

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.

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().

Theme © iAndrew 2016 - Forum software by © MyBB