What does " :: " mean in PHP?

Asked

Viewed 2,872 times

4

In PHP, what do these four dots mean "::" ?

I see a lot in things like: stackoverflow::class

1 answer

9


These four dots mean that you are calling a static method a class. A static method can be called without the need to instantiate a class object. Ex:

Class teste() {
  public function metodoTradicional() {
    echo 'Tradicional';
  }
  public static function metodoEstatico() {
    echo 'Estático';
  }
}

teste::metodoTradicional(); // vai dar erro
teste::metodoEstatico(); // vai imprimir 'Estático'

More about static methods you can read in the official documentation: http://php.net/manual/en/language.oop5.static.php

  • Got it, too much dough! Thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.