I'd like to know if there's a technical reason of why PHP's designers decided to invoke a static method using Class::static_method() instead of Class->static_method() (like any other method). Does the syntax change reflect any technical requirement?

I'm asking this because the syntax for every single other language I know to invoke a method is always the same, despite it being static or not.

  • 2
    it imitates C++ in that; it has 3 different ways to invoke methods: the dot for references and values, the arrow for pointers and the double colon for statics – ratchet freak Nov 21 '13 at 19:23
  • @ratchetfreak does that make any easier to parse the code? – Geeo Nov 21 '13 at 20:23

Invocation of instance methods is not Class->method() but $object->method(). Additionally, semantics of the -> operator is that it passes the instance of the class (vulgo: object) to the method in a hidden parameter; class methods differ from instance methods in that they, at best, have access to class attributes.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.