我一直面臨一個奇怪的問題,我不能得到解決。長話短說,當我參加一個我正在創建的遊戲的迷你遊戲時,它會很好!但是當我退出迷你遊戲的時候,它應該把我送回房間,但是卻給了我一個錯誤。PHP可捕獲的致命錯誤:參數1傳遞給必須是類型數組,null給出,在行208中調用並定義
這是錯誤:
PHP Catchable fatal error: Argument 1 passed to Sweater\Server::leaveTable() must be of the type array, string given, called in /usr/share/nginx/Sweater/Sweater/GameHandler.php on line 208 and defined in /usr/share/nginx/Sweater/Sweater/GameHandler.php on line 184
我做了一些研究提出這個問題之前試過,我遇到了解決方案,但遺憾的是他們沒有工作。
GameHandler.php handleLeaveTable:
function handleLeaveTable(Array $arrData, Client $objClient) {
$intPlayer = $arrData[0];
$this->leaveTable($intPlayer); // Line 208
}
GameHandler.php leaveTable:
function leaveTable(Array $arrData, Client $objClient) { // Line 184
$intPlayer = $arrData[4];
$tableId = $intPlayer->tableId;
if($tableId !== null) {
$seatId = array_search($intPlayer, $this->playersByTableId[$tableId]);
$opponentSeatId = $seatId == 0 ? 1 : 0;
if(isset($this->playersByTableId[$tableId][$opponentSeatId])) {
$this->playersByTableId[$tableId][$opponentSeatId]->addCoins(10);
}
unset($this->playersByTableId[$tableId][$seatId]);
unset($this->tablePopulationById[$tableId][$intPlayer->$strUsername]);
$objClient->sendXt('ut', $objClient->getIntRoom(), $tableId, $seatId);
$intPlayer->tableId = null;
if(count($this->playersByTableId[$tableId]) == 0) {
$this->playersByTableId[$tableId] = array();
$this->gamesByTableId[$tableId] = null;
}
}
}
問題是什麼嗎?我檢查了一切,無法找到解決方案。
編輯,什麼$ arrData是:
function decodeData($strData){
$arrData = simplexml_load_string($strData, 'SimpleXMLElement', LIBXML_NOCDATA);
if($arrData === false){
throw new Exceptions\HandlingException('Unable to parse client\'s XML data');
}
$arrData = json_decode(json_encode((array)$arrData), true);
return $arrData;
}
function handleData($strData, $objClient){
$arrData = explode($this->arrConfig['Packets']['Delimiter'], $strData);
array_pop($arrData);
foreach($arrData as $strData){
Silk\Logger::Log('Received data: ' . $strData);
$strSubstring = substr($strData, 0, 1);
$blnPossibleXML = $strSubstring == '<' ? true : false;
$blnPossibleGame = $strSubstring == '%' ? true : false;
if($blnPossibleXML === false && $blnPossibleGame === false){
throw new Exceptions\HandlingException('Bad client detected!');
}
$blnPossibleXML ?
$this->handleXMLData($strData, $objClient):
$this->handleGameData($strData, $objClient);
}
unset($arrData);
}
所以我應該切換$ arrData與$ objClient或刪除$ arrData第5個元素? – SunleafStudios
'$ arrData'包含什麼? –
我會爲您查找並編輯我的問題。等一下! – SunleafStudios