Hi, I am quite new to OOP concept. I'm confused with the usage of :: in PHP5. As i understand the :: is mostly used for statics method or parent to access an overridden method. But, under what situation we need to use statics method? Could somebody explain to me? Thank you.
Static methods can be called without an object reference. They are also known as class methods since they operate on the class itself rather than an instance of the class. Since calling mechanism uses the class name static methods can be called from anywhere without any scoping issues.
These features are both beneficial and restrictive. The benefits tend to be more obvious and can be seen in such things as Factory methods and the Singleton pattern. The major drawback with static methods is that they are not object-oriented. One can't change the behavior of a class, whereas one can change the behaviour of an object. That is, as soon as you tie your code into the ClassName::ClassMethod() syntax you restrict the ability to use inheritance, polymorphism, encapsulation - the pillars of OO.
Bookmarks