[英]visibility of the static private variable in it's class php
I have the following code:我有以下代码:
myClass extends Class{
private static $var1 = 0;
public function index(){
if(some condition){
$this->var1 = 1;
}
}
public function success(){
if($this->var1 == 0){
...
}else{
...
}
}
}
?>
My problem is that I cannot access the var1 from the functions in the class.我的问题是我无法从类中的函数访问 var1。 What am I doing wrong here?
我在这里做错了什么?
Static variables (and methods) are accessed using the ::
operator.使用
::
运算符访问静态变量(和方法)。 To access $var1
within the class, use the following code instead:要在类中访问
$var1
,请改用以下代码:
myClass extends Class{
private static $var1 = 0;
public function index(){
if(some condition){
static::$var1 = 1;
}
}
public function success(){
if(static::$var1 == 0){
...
}else{
...
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.