展开全部
case-1:给类中的静态变量赋值62616964757a686964616fe59b9ee7ad9431333337623437:class PHPJungle{
private static $__instance = null;# 类中的私有成员:静态变量
public function __construct(){
}
public static function getInstance(){
if(self::$__instance instanceof self)
return self::$__instance; # 给静态变量赋值
return new self();
}
public function anyMethod(){
echo 'Hello world!','
';
return;
}
}
$PJ = new PHPJungle();
$PJ->getInstance()->anyMethod();
case-2:给函数中的局部静态变量赋值:function hello(){
static $total = 0;
echo $total,'
';
$total++; # 给函数中的局部静态变量赋值
}
hello();# 0
hello();# 1
hello();# 2