コードで次の 2 つのエラーが発生しました。
注意: 未定義の変数: C:\Program Files (x86)\Zend\Apache2\htdocs\ttt.php の 61 行目の p1
Notice: 61 行目で C:\Program Files (x86)\Zend\Apache2\htdocs\ttt.php の非オブジェクトのプロパティを取得しようとしています。
関連するコードは次のとおりです。
//this is within the Board object
function updateBoard(){
if($this->xTurn == True){
echo "It is " . $p1->username . "'s turn: "; //line 61
} elseif($this->xTurn == False){
echo "It is " . $p2->username . "'s turn: ";
}
}
//This is within the Player object
function __construct($name){
$this->username = $name;
}
$a = new Board();
$p1 = new Player($name);
$p2 = new Player($name);
$new = new Game();
$a->updateBoard
これを実行するたびに、$p1->username がエコーされません。現時点ではわからないので、これを修正する方法についての考え。
更新:おっと。いくつかの重要なコードを省略しました。