spires Posted April 27, 2010 Share Posted April 27, 2010 Hi I'm just learning OOP, and can't seem to get me head around why you would choose to use a static variable over creating a new instance. They both do the same thing (return a value), so why use one over the other? Does it make the code cleaner, quicker etc? Thanks Link to comment https://forums.phpfreaks.com/topic/199890-oop-instance-vs-static/ Share on other sites More sharing options...
Mchl Posted April 27, 2010 Share Posted April 27, 2010 static variables are common for all object of given class. Instance variables are not (each object has it's own.. instance of such variable). You can use static variables for example to keep counter of how many objects of given class have been created. Link to comment https://forums.phpfreaks.com/topic/199890-oop-instance-vs-static/#findComment-1049182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.