我一直用PHP创建一些代码,而我服务器的日志一直显示以下错误。代码是我一直在创建的游戏的处理程序。我试图通过研究和应用修复''来解决这些问题。但它并没有顺利进行。
未定义索引:#jt in 第160行/usr/share/nginx/Sweater/Sweater/GameHandler.php 未定义的索引:#jt in 第161行/usr/share/nginx/Sweater/Sweater/GameHandler.php 未定义的索引:#jt in 第167行/usr/share/nginx/Sweater/Sweater/GameHandler.php 未定义的索引:#lt in 第227行/usr/share/nginx/Sweater/Sweater/GameHandler.php
尝试获取非对象的属性 第302行/usr/share/nginx/Sweater/Sweater/GameHandler.php
这是他们的代码:
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);
}
}
这里发生了什么?
答案 0 :(得分:0)
$this->tablePopulationById[$tableId]
tablePopulationById
是一个不包含索引$ tableId的键的数组。
$arrData[3];
不包含您期望的任何课程的对象!
在这两种情况下,var_dump他们看看你有什么!
var_dump($this->tablePopulationById);
var_dump($arrData);