Liquid Fire Posted December 2, 2007 Share Posted December 2, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/79863-static-meber-vs-non-static-member/ Share on other sites More sharing options...
Jenk Posted December 3, 2007 Share Posted December 3, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/79863-static-meber-vs-non-static-member/#findComment-404567 Share on other sites More sharing options...
448191 Posted December 3, 2007 Share Posted December 3, 2007 Now that being said is there any speed difference from static to non-static members with singleton classes? Not much, I reckon. Do some benchmarks and find out for yourself. Quote Link to comment https://forums.phpfreaks.com/topic/79863-static-meber-vs-non-static-member/#findComment-404838 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.