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

问题描述:

我一直面临一个奇怪的问题,我不能得到解决。长话短说,当我参加一个我正在创建的游戏的迷你游戏时,它会很好!但是当我退出迷你游戏的时候,它应该把我送回房间,但是却给了我一个错误。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); 
    } 

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

$arrData你把它串

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

的第一个元素在GameHandler.php handleLeaveTable:

你拿第一元素形成一个数组

然后在GameHandler.php leaveTable:

您试图访问该元素作为一个数组,然后采取

+0

所以我应该切换$ arrData与$ objClient或删除$ arrData第5个元素? – SunleafStudios

+0

'$ arrData'包含什么? –

+0

我会为您查找并编辑我的问题。等一下! – SunleafStudios