PHP code Common "::" Operators, this is the scope of the qualified operator, which is used to pin class in the non-scoped level, the left is the scope, the right is the access scope of the members.
Scoped operator (also known as: Range resolution operator) or, more simply, a pair of colons,
Can be used to access static members, methods, and constants, and can also be used to override members and methods in a class.
The scope defined in PHP has self and parent, and the static scope is provided in PHP6.
Self: Represents the scope of the current class, cannot use self in code outside the class, and when using self in an extension class, it calls a method other than the parent class, but instead extends the overloaded method of the class.
Parent: Represents the scope of the current class parent class.
<?php
Class forasp{
Static $url="http://www.4u4v.cn";
Static $webname = "Web production learning php double colon";
Public function writeurl(){
Echo self::$url; //call your own content
}
Public function writewebname(){
Echo "test subclass calls parent class content";
}
}
Class cn extends forasp{
Function father(){
Parent::wirtewebname();
}
}
$a = new forasp();//instantiating the parent class
$a->writeurl();//call its own content
$b = new cn();
$b->writewebname();//call parent content
?>
When you call a static method, you can use:: Call a static method or property in a class.
Usage:
The double-colon operator, the scope-scoped operator, scope Resolution operator can access properties and methods overridden in static, const, and class.
So, what is the difference between the application and the arrow-----operator?
When you access these static members, methods, and constants outside of the class, you must use the name of the class.
The double-colon range-resolution operator is typically used in static methods, static variable calls, where the class does not need to be instantiated.
With the arrow operator, you must instantiate the class (or you can call it inside the class).