This is my Code:
class content
{
public $text;
public static $total;
function __construct($content){
$this->text = $content;
$this->total = 0;
}
public static function vote(){
self::$total++;
}
}
$foo = new content("hai");
echo "<pre>";
print_r($foo);
echo "</pre>";
$foo::vote();
echo "<pre>";
print_r($foo);
echo "</pre>";
The output:
Strict Standards: Accessing static property content::$total as non static in C:\Users\jodi\Documents\Visual Studio 2013\Projects\FinalProject\FinalProject\index.php on line 10
content Object ( [text] => hai [total] => 0 )
content Object ( [text] => hai [total] => 0 )
the $total
is not change.
and got error. -,-
How to increment $total
?
is there any alternative way??
$total
in the constructor as an object variable but you've declared it to be a class variable. Why is the methodvote()
declared as a class method?