Home >Backend Development >PHP Tutorial >PHP: Example code sharing of range parsing operator (::)
Scope parsingThe operator (::) is a pair of colons that can be used to access static members, methods and constants , as well as members and methods in the overridden class.
When using the :: notation outside a class to access these static members, methods, and constants, the name of the class must be used, as shown in the following example.
<?php Class Person{ // 定义静态成员属性 public static $country = "中国"; // 定义静态成员方法 public static function myCountry() { //内部访问静态成员属性 echo "我是".self::$country."人<br />"; } } // 输出静态成员属性值 echo Person::$country."<br />"; // 访问静态方法 Person::myCountry(); ?>
Use the :: symbol to access static members and methods. For more information, please refer to "PHP Static (static)".
class Person { var $name; var $sex; var $age; function say() { echo "我的名字叫:".$this->name."<br />"; echo "性别:".$this->sex."<br />"; echo "我的年龄是:".$this->age; } } class Student extends Person { var $school; function say() { parent::say(); echo "我在".$this->school."上学"; } }
The above is the detailed content of PHP: Example code sharing of range parsing operator (::). For more information, please follow other related articles on the PHP Chinese website!