Possible Duplicate:
In PHP, whats the difference between :: and -> ?
This a continuation from my previous question – however I think its unique enough to warrant a new question.
What is the difference between:
Message::listMessages();
and
$message->listMessages();
I’m creating a mini-cms and I want a system that displays errors in a uniform fashion.
Cheers,
Keiran
Static methods come handy when we want to share
information between objects of a class, or want to represent something
that’s related to the class itself, not any particular object.
The difference between the two is in the way they are invoked.
For example,
Message::listmessages()is a static method and can be called like this:You do not need to first make an object of class Message, in order to use the above. Also, note that this should be used when you want to return a result on definite pre-configured variables, and is not based on properties of class Message
However,
$message->listmessages()is an instance method and can be called like this:This is used for generic occassions when you want to call a function on runtime properties of class Message.