我一直在PHP中創建一些代碼,並且我的服務器的日誌不斷顯示以下錯誤。這些代碼是我一直在創建的遊戲的處理程序。我試圖通過研究和應用「修復」來修復它們,但它並不順利。PHP注意:未定義的索引錯誤
未定義指數:一個#JT在 /usr/share/nginx/Sweater/Sweater/GameHandler.php上線160 未定義指數:在 的/ usr /股#JT/nginx的/毛衣/毛衣/GameHandler.php 161行 未定義索引: 中的#jt行167上的/usr/share/nginx/Sweater/Sweater/GameHandler.php 未定義索引:a#lt /usr/share/nginx /毛衣/Sweater/GameHandler.php 227行
嘗試獲取非對象的屬性 /usr/share/nginx/Sweater/Sweater/GameHandler.php 30行2
這是他們的代碼:
function handleJoinTable(Array $arrData, Client $objClient) {
$intPlayer = $arrData[4];
$tableId = $arrData[2];
$strUsername = $this->objDatabase->getUsername($intPlayer);
$seatId = count($this->tablePopulationById[$tableId]) - 1; // Line 160
if($this->gamesByTableId[$tableId] === null) { // Line 161
$findFourGame = new FindFour();
$this->gamesByTableId[$tableId] = $findFourGame;
}
$this->tablePopulationById[$tableId][$strUsername]; // Line 167
$seatId += 1;
$objClient->sendXt('jt', $objClient->getIntRoom(), $tableId, $seatId);
$objClient->sendXt('ut', $objClient->getIntRoom(), $tableId, $seatId);
$this->playersByTableId[$tableId][] = $intPlayer;
$this->tableId = $tableId;
}
function handleLeaveTable(Array $arrData, Client $objClient) {
$intPlayer = $arrData[2];
$tableId = $arrData[3];
$strUsername = $this->arrClientsByID[$intPlayer]; // Line 227
unset($objClient->arrPlayer[$intPlayer]);
$objClient->sendXt('lt', $objClient->getIntRoom(), $strUsername);
}
function handleGetGame(Array $arrData, Client $objClient) {
$intPlayer = $arrData[3];
if($objClient->getExtRoom() == 802) {
$puckData = $this->rinkPuck;
$objClient->sendXt('gz', $objClient->getIntRoom(), $puckData);
} elseif($intPlayer->tableId !== null) { // Line 302
$tableId = $intPlayer->tableId;
$playerUsernames = array_keys($this->tablePopulationById[$tableId]);
@list($firstPlayer, $secondPlayer) = $playerUsernames;
$boardString = $this->gamesByTableId[$tableId]->convertToString();
$objClient->sendXt('gz', -1, $firstPlayer, $secondPlayer, $boardString);
}
}
這是怎麼回事?
請具體告訴我們代碼行說的是什麼。某些數組鍵缺少它正在討論的內容,另一個錯誤是您沒有類的實例,所以無法訪問任何屬性! – delboy1978uk
我在發生問題的代碼中添加了註釋。 – SunleafStudios
看看['isset'](http://php.net/manual/en/function.isset.php)。你的支票似乎有缺陷(161)。檢查'tableId'是你認爲的。 – ficuscr