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. 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:
myClass extends Class{
private static $var1 = 0;
public function index(){
if(some condition){
static::$var1 = 1;
}
}
public function success(){
if(static::$var1 == 0){
...
}else{
...
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.