Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.