You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
689 B
31 lines
689 B
<?php
|
|
/**
|
|
* 静态的作用是不用通过实例话,
|
|
* 直接通过区域操作符:: 访问调用
|
|
*/
|
|
|
|
class ClassA{
|
|
//静态属性
|
|
public static $varA="这是一个静态属性";
|
|
|
|
//静态方法
|
|
public static function fnA() {
|
|
echo "这个一个静态方法".PHP_EOL;
|
|
}
|
|
|
|
//对比this->和self::
|
|
public static function fnB(){
|
|
// echo $this->$varA; //this要通过对象来使用
|
|
echo self::$varA;
|
|
}
|
|
}
|
|
|
|
//访问静态属性
|
|
echo ClassA::$varA.PHP_EOL;
|
|
|
|
//访问静态方法
|
|
ClassA::fnA();
|
|
|
|
//对比this->和self::
|
|
ClassA::fnB();
|
|
?>
|