The operator of "::" is common in PHP code. This is the scope limiting operator. It is used to set the level of the unavailable scope in the top class. The left side is the role. Domain, on the right are members of the access scope.
The scope qualification operator (also known as: scope resolution operator) or more simply a pair of colons,
can be used to access static members, methods and Constant can also be used to override members and methods in a class.
The scopes defined in PHP are self and parent, and static scope is provided in PHP6.
self: Indicates the scope of the current class. Self cannot be used in code outside the class. When self is used in an extended class, it does not call the method of the parent class, but the overloaded method of the extended class. .
parent: Indicates the scope of the parent class of the current class.
<?php class forasp{ static $url="http://www.4u4v.cn"; static $webname = "网站制作学习之php双冒号"; public function writeurl(){ echo self::$url; //调用自己的内容 } public function writewebname(){ echo "测试子类调用父类内容"; } } class cn extends forasp{ function father(){ parent::wirtewebname(); } } $a = new forasp();//实例化父类 $a->writeurl();//调用自身内容 $b = new cn(); $b->writewebname();//调用父类内容 ?>
When calling static methods, you can use :: to call static methods or properties in the class.
Usage:
The double colon operator is the scope limiting operator Scope Resolution Operator, which can access static, const, and overridden properties and methods in classes.
So, what is the difference in application with the arrow-> operator?
When accessing these static members, methods and constants outside the class, the name of the class must be used.
The double-colon range resolution operator is generally used in calls to static methods and static variables. At this time, the class does not need to be instantiated.
When using the arrow operator ->, the class must be instantiated (or called inside the class).
The above is the detailed content of Introduction to the meaning of the double colon::range parsing operator in PHP. For more information, please follow other related articles on the PHP Chinese website!