SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Statics Methods

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2006
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Statics Methods

    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.

  2. #2
    SitePoint Addict
    Join Date
    Jan 2005
    Location
    United Kingdom
    Posts
    208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •