What are the two double points (::) for?

Asked

Viewed 338 times

3

I see in some classes something like this:

Illustrative class

class Carro
{
    private static $quantidade = 5;

    public function getQuantidade()
    {
        return self::$quantidade;
    }

    public function comprar()
    {

        self::$quantidade--;
    }
}

What I want to know is this, the operator self calls the variable using two points self::. After all, what is this type of call for? Why was it used in this way and not using the operator $this => $this->$quantidade ?

  • 4

    The two questions should already answer enough, but in short: It aims to make calls to methods and static and constant properties of the class.

  • @Wallacemaxters thanks, I’ll give a read :)

  • 1

    Summarizing the double column serves to access static members of a class

No answers

Browser other questions tagged

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