Class Question - Help for Beginners

Possible duplicate:
In PHP, what is the difference between :: and →?

This is a continuation of my previous question - however, I find it unique enough to guarantee a new question.

What's the difference between:

Message::listMessages(); 

and

$message->listMessages(); 

I create mini cms and I want the system to display errors uniformly.

Cheers, Keiran

+3
source share
6 answers

Static methods come in handy when we want to share information between objects of a class or want to represent something that is related to the class itself, and not to any specific object.

, . , Message::listmessages() :

$messages = Message::listmessages($args);

Message, . , , Message

$message->listmessages() :

$message = new Message();
$messages->$args = $args
$messages= $message->listmessages();

, Message.

+1

,

Message::listMessages(); C C++

, PHP is $message->listMessages();

.

+1

, Message :

class Message {
  //...
  static function listMessages() {
    //...
  }
  //...
}

, listMessages Message, $message->listMessages() .

: :

$ php5-cgi 
<?php
class A { static function f() { }
          function f() { } }
?>
PHP Fatal error:  Cannot redeclare A::f() in - on line 2
Status: 500 Internal Server Error
X-Powered-By: PHP/5.3.2-1ubuntu4.5
Content-type: text/html
+1

, :

Message::listMessages();

, .. ( ):

$message->listMessages();
+1

Message:: listMessages() - , , listMessages() propretyes, .. ... . (static , Message)

$message- > listMessages() propretyes, Message propretyes (, $messages $messages1).

+1

Message , , , .

Message::listMessages(); 

The class object Messagecalls a public method

$message->listMessages();
0
source

Source: https://habr.com/ru/post/1779127/


All Articles