在php对象中,为什么静态变量只能用:: notation访问,但静态方法可以从::& - >调用

In PHP, for e.g. you define a variable & method static in a class. For its objects, why we can only access variables with :: notation while we can run static methods with -> or :: both? Why this dual behaviour?

class first {
    //variable
    public static $var=5;

    //method
    static function new(){
        echo "<br>";
        echo self::$var;
        echo "<br>";
    }
}

class second {

}

$obj = new first();

echo $obj->$var; // this throws an error
echo $obj::$var; // this runs
$obj->new(); // this also runs
$obj::new(); // this runs

Although arbitrary, a static class variable only belongs to a class, not to an object. A static class method belongs to both a class and an object of that class.

As demonstrated below, changing a static variable of a class would change the variable in all instances of that class. So the -> notation would be deceitful. This does not happen with a static class method.

Imagine that -> would be allowed on static variables, then

calling $someObjectOfTypeX->some_static_variable = 'some_value' would change the state of $anotherObjectOfTypeX.

Calling $someObjectOfTypeX->someStaticFunction() however, does not change the state of $anotherObjectOfTypeX.

Although the keyword static is identical it has different implications for functions and variables. Static variables are shared by all instances of a class. Static function don't alter the objects state and therefore also will not change the state of other instances of the same class.

<?php

class first
{
    //variable
    public static $var = 5;

    //method
    static function new()
    {
        echo "<br>";
        echo self::$var;
        echo "<br>";
    }
}

$obj1 = new first();
$obj2 = new first();

echo $obj1->var; // this throws an error
echo $obj1::$var; // this runs
echo first::$var; // this runs

$obj2::$var = 10; // changes $var in class first (both object $obj1 and object $obj2)
$obj2->var = 15; // this throws an error (if it didn't it would change the variable also in $obj1)

$obj1->new(); // this also runs
$obj1::new(); // this runs
first::new(); // this runs