【发布时间】:2018-03-20 16:36:21
【问题描述】:
我有以下代码:
myClass extends Class{
private static $var1 = 0;
public function index(){
if(some condition){
$this->var1 = 1;
}
}
public function success(){
if($this->var1 == 0){
...
}else{
...
}
}
}
?>
我的问题是我无法从类中的函数访问 var1。我在这里做错了什么?
【问题讨论】:
-
因为
this不是self -
阅读 PHP OOP 中的 static properties。
标签: php variables scope static private-members