PHP Catchable致命错误:传递给的参数1必须是类型数组,给定null,在第208行调用并定义

时间:2017-08-24 13:06:39

标签: php

我一直面临着一个我无法解决的奇怪问题。长话短说,当我加入一个迷你游戏,我正在创建一个游戏时,它很好!但是当我退出迷你游戏时,它应该把我送回房间,但它会给我一个错误。

这是错误:

  

PHP Catchable致命错误:参数1传递给   Sweater \ Server :: leaveTable()必须是数组类型,字符串给定,   第208行/usr/share/nginx/Sweater/Sweater/GameHandler.php中调用   并在/usr/share/nginx/Sweater/Sweater/GameHandler.php中定义   第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);
    }

1 个答案:

答案 0 :(得分:0)

  

PHP Catchable致命错误:参数1传递给   Sweater \ Server :: leaveTable()必须是数组类型,字符串给定,   第208行/usr/share/nginx/Sweater/Sweater/GameHandler.php中调用   并在/usr/share/nginx/Sweater/Sweater/GameHandler.php中定义   第184行

$arrData开始,您将获取第一个字符串

$intPlayer = $arrData[0];
$this->leaveTable($intPlayer); // Line 208

GameHandler.php handleLeaveTable:

您将第一个元素形成一个数组

然后在GameHandler.php leaveTable:

您正尝试将该元素作为数组访问,然后使用第5个元素