<?php
class Dribble {
public $shotCount = 0;
private $shot = false;
public function shotPosted() {
$shot = true;
if ($shot == true) {
$shotCount++;
echo $shotCount;
}
if ($shotCount >= 7) {
exit("You've reached your monthly goal!");
}
}
}
$shot1 = new Dribble();
$shot1->shotPosted();
$shot2 = new Dribble();
$shot2->shotPosted();
我對面向對象的PHP有點新,我目前正在研究一個有點困難的問題。 任何輸入將不勝感激。先謝謝你。面向對象的計數器
'if($ shot = true)'應該是'if($ shot == true)'。 '='是賦值,'=='是比較。 – Barmar
你需要爲你的函數 – cmorrissey