A double colon is usually called by a static method, a static variable, and the class does not need to be instantiated at this time. Instead of using the arrow operator->, you must instantiate the class (or call it inside the class). )
A double colon (::) is a positional access symbol. Not just static methods and variables. Instead, it means calling the colon to the left of this lump called the right side of the colon. Such a meaning. So.. The left cannot write $self. Because $self is parsed first, unless $self is defined earlier, the variable is pointing to itself.
In the latest version of PHP. A double colon is a way to follow this function completely. Can replace-> Invoke object variable. Because it's a positional indicator.
In order to distinguish between the methods and properties of an object, and to access static and static variables of a class, static and static variables of the class are common to the class, do not need to be instantiated and can be accessed, and the methods and properties of the objects are unique to each object and must be instantiated first. Other languages, such as C++,java, are the same (although they may not provide the same access symbols)
-> is the method and property that accesses the object:: Is the static method and static variable that accesses the class
Object access and:: Location access
The theory part, as everyone has said before, is indeed true. But PHP is a little different.
In the default configuration, PHP is not strictly required:: The static method must be called
Test the following code to know
Class t{public $v = 1; Public Function GetVar () { return 1;//$this->v; }} Class Xxxxx{public function Actionindex () {$x = T::getvar (); $t = new T (); $x = $t->getvar (); }} Author: Chu Tianle Link: https://www.zhihu.com/question/19782824/answer/35943595 Source: The copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.