Jump to content

static meber vs non-static member


Liquid Fire

Recommended Posts

As i am developing my framework and trying to think of any speed issue to get as much as i can I stated to think about my static members in my base class.  right now I have a static instance of my database, url_helper, session, and configuration classes.  Now all of these classes bug the database class is a singleton class.  is there any speed difference from using a static member of a singleton class.  I know a common way of loading classes like these are to load them dynamically from an array in the constructor however, unless i am mistaken, those variables are than public to access outside of the class which breaks encapsulation(I am a firm believer that data should always been hidden from the rest of the code and only accessible thought accesser functions).  Now that being said is there any speed difference from static to non-static members with singleton classes?

Link to comment
https://forums.phpfreaks.com/topic/79863-static-meber-vs-non-static-member/
Share on other sites

If the value is a value that is shared amongst all objects of that class, and must be the same amongst all instances, or is for use within static methods, then it should be static, or perhaps constant if the value never changes. If the value is individual for each instance, then it must be non-static.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.