I hope that this will help to understand how to work with static variables inside a class

I hope that this will help to understand how to work with static variables inside a class


bar;    }            
}

$ob = new a();
a::getFoo();     // output: I am foo    
$ob->getFoo();    // output: I am foo
//a::getBar();     // fatal error: using $this not in object context
$ob->getBar();    // output: I am bar
                // If you keep $bar non static this will work
                // but if bar was static, then var_dump($this->bar) will output null 

// unset($ob);
a::setFoo();    // The same effect as if you called $ob->setFoo(); because $foo is static
$ob = new a();     // This will have no effects on $foo
$ob->getFoo();    // output: I am a new foo 

?>

你可能感兴趣的:(I hope that this will help to understand how to work with static variables inside a class)