Extracting two key points from the definition of this name, 1th static, that is, this function only applies to static properties or static methods.
2nd delay binding, which can be well understood according to the following code
Take a look at this example:
classa{Static $name= "Tom"; Public functionPrintname () {EchoSelf::$name." \ n "; Self::Fun (); } Static functionFun () {Echo"A class\n"; }}classBextendsa{Static $name= "Jon"; Static functionFun () {Echo"B class\n"; }}$obj=NewB ();$obj-printname ();//output result//tom//A Class
I used the Self keyword in the Printname function, and self is the pointer to the current class,
So many people would ideally think the output would be like this:
// join//B Class
In this case, when defining Class A, a static method or property is called with the Self keyword inside the function printname.
But once this function is defined, the static methods and properties of Class A are bound to the function, and do not ask why, PHP is so implemented,
But now we want to achieve this effect, that is, the function is defined after the use of static methods and properties do not immediately bind to death,
Instead, the binding is determined based on the class that is ultimately inherited.
So PHP used the static keyword after 5.5 to solve the problem, the following code example:
classa{Static $name= "Tom"; Public functionPrintname () {Echo Static::$name." \ n "; Static::Fun (); } Static functionFun () {Echo"A class\n"; }}classBextendsa{Static $name= "Jon"; Static functionFun () {Echo"B class\n"; }}$obj=NewB ();$obj-printname ();//Output//join//B Class
You can explore your own usage scenarios in your project, such as a member of the parent class Vip
The following two sub-categories are super member SVIP and annual fee member YVIP
You can override the static UserGroup () method or other static property, respectively, in two subclasses, using lazy static bindings in the parent class
So you can write very elegant code.
PHP "Lazy static binding" function, static