What does :: (double colon) in php mean? What is the difference between -> in PHP

The :: (double colon) in PHP is a built-in syntax analysis symbol, also known as the "scope analysis operator". :: is usually used to access static members, which means that you can use it directly without instantiating the object

What does :: (double colon) in php mean? What is the difference between -> in PHP

class Test{
    public static $test = 1;
    public static function test(){

    }
}

Test::$test; //获取$test属性的值bai   static 静态的
Test::test(); //调用静态方法test()

-> in PHP is the method and attribute used to refer to the class instance

class Test{
    function add(){return $this->var++;}
    var $var = 0;
}
 
$a = new Test; //实例化对象名称
echo $a->add();
echo $a->var;

Summary: The difference between :: and -> in PHP is :: used to access static methods and properties, -> access to instantiated methods and properties

 

Guess you like

Origin blog.csdn.net/qq_39339179/article/details/112241604