Welcome Guest, Not a member yet? Register   Sign In
Can you have too many static functions?
#6

(06-29-2015, 07:23 AM)mwhitney Wrote:
(06-27-2015, 01:16 AM)jLinux Wrote:
(06-27-2015, 12:52 AM)ivantcholakov Wrote: It is unknown practice, it is hard to say.
As far as I know, loading a model with a different property name in the controller instance makes a new instance of the model.

Right, but if the model is configured to auto load, then its just loaded once, thus its no big deal?... Just didnt want to fill my entire project up with static references, then find out it was a bad idea

If you're only loading the model once, why are you using static properties/methods? Your static method doesn't work without the constructor, and the static $db property duplicates the inherited $this->db.

Generally, the purpose of static properties/methods in a class are to allow multiple instances of a class to share some data, or to make the methods available without having to instantiate the class.

Since CI loads everything into a singleton, the use cases for static properties/methods are diminished, as you usually have only one instance of each class, and most of those classes are accessible from any other loaded class through the CI instance.

Your very last sentence..

Quote:Since CI loads everything into a singleton, the use cases for static properties/methods are diminished, as you usually have only one instance of each class, and most of those classes are accessible from any other loaded class through the CI instance.
Is something I realized shortly after this thread, so yeah, reverted my changes. THANKS!
Reply


Messages In This Thread
RE: Can you have too many static functions? - by jLinux - 07-05-2015, 03:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB