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
?
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.
– Wallace Maxters
@Wallacemaxters thanks, I’ll give a read :)
– Jorge.M
Summarizing the double column serves to access static members of a class
– Marcos Brinner