2015-09-02 54 views
0
public function updateFaction() 
{ 
    $this->plugin->getServer()->getLogger()->info("Updating Faction..."); 
    foreach($this->plugin->getFactions() as $faction) 
    { 
     $this->plugin->getServer()->getLogger()->info("test"); 
     if($faction->hasPlayer($this->player)) 
     { 
      $this->faction = $faction->getName(); 
      return true; 
     } 
     $this->faction = null; 
    } 
} 

當我在控制檯中運行此代碼(使用Pocketmine API)時,它打印出「Updating Faction ...」但從未到達下一行並且不打印出「測試」。我覺得我在這裏沒有看到一些愚蠢的錯誤,但它讓我難倒了。跳過不明原因的代碼行

+1

你調試了你的代碼嗎? '$ this-> plugin-> getFactions()'包含什麼? – PeeHaa

+1

當你嘗試'var_dump($ this-> plugin-> getFactions())時,你會得到什麼數據;'? – AmitM

+0

你也可以嘗試'...-> getLogger() - > info(count($ this-> plugin-> getFactions()));'看看你是否有多個項目可以迭代 –

回答

0

當我將腳本從php5.5移動到php 5.2 server時,我遇到了這個問題。幾個小時後,我發現問題是由於行終止字符。因此,終止於CRLF的行會被執行,而終止於CR的行會被跳過。爲了解決這個問題,我簡單地將腳本複製到記事本(或任何基本的文本編輯器)並保存回到同一個文件,並且所有的工作都像在5.5服務器上那樣工作。