Static variables and static methods of the PHP class

Why objects outside the class can access static methods, but not static variables

class Test
{
    public static $num = 100;
    public static function abc()
    {
        echo "";
    }
}
$t = new Test();
$t->abc();
// notice
echo $t->num;

Thank you for your help

Php
Apr.29,2021

The static member properties and static member methods of the

class are accessed through the class name:: [property name / method name] . The instantiated object of the class can be instantiated via self:: [property name / method name] .

as far as I understand it, static members are class, not object, so there is no way to access them through objects. If necessary, you can add the specified method to the object to modify it.


first of all, the document has a specific description of this point link
clipboard.png



echo $tvana

Menu