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:
$messages = Message::listmessages($args);
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:
$message = new Message();
$messages->$args = $args
$messages= $message->listmessages();
This is used for generic occassions when you want to call a function on runtime properties of class Message.