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:
$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.
As i understood your question,
we are using this way Message::listMessages(); in C and C++
but right syntax we are using in PHP is $message->listMessages();
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With