php中的static:
1:属于静态变量:;
2:是全部类的属性;
3:调用静态变量要用::(两个冒号)。
eg:1
<html>
<head>
<title>static测试</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<?PHP
class Person{ static $type = "人物";
public $name = "张三";
public $age = 18; public function intro(){
echo Person::$type."<br/>".$this->name."<br/>".$this->age."<br/>";
}
} $p1 = new Person(); $p1->intro();
?>
</body>
</html>
eg:2
<html>
<head>
<title>static测试</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<?PHP
class Person{ static $type = "人物";
public $name = "张三";
public $age = 18; public function intro(){
echo Person::$type."<br/>".$this->name."<br/>".$this->age."<br/>";
}
} $p1 = new Person();
Person::$type = "张三不是人!"; $p1->intro();
?>
</body>
</html>
eg:3
class类的继承
<html>
<head>
<title>class类的继承</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<?PHP
class Person{ static $type = "人物";
public $name = "张三";
public $age = 18; public function intro_Person(){
echo $this->name."<br/>".$this->age."<br/>";
}
} class Teacher extends Person{ public function intro_Teacher(){
echo $this->age;
} } class Students extends Teacher{ public function intro_Students(){
echo $this->age;
} } $p1 = new Students(); $p1->intro_Students();
?>
</body>
</html>