In PHP, methods and properties are in a separate namespace (you can have a method and a property with the same name).
Следователно можем да имаме:
class Value
{
private int $value;
public function __construct(int $value)
{
$this->value = $value;
}
private function value() : int
{
return $this->value * 2;
}
}
Whether you are accessing a property or a method depends of the syntax you are using to do so.
$expr->value()
is a method call, so PHP will search something
in the class’ list of methods.
$expr->value
is a property fetch, so PHP will search something
in the class’ list of properties.