2015-10-15 34 views
0

所以我做了一些測試條件,出於某種原因,我不能讓這個函數達到最內層的if/else。PHP函數沒有達到最內層的嵌套if塊

我希望有人能告訴我我做了什麼?

function verifyStridersIdentity($post_name, $modpass) { 
    //is the post name strider? 
    //this part works 
    if (strtolower($post_name) == 'strider') { 
     //is the mod pass set? 
     //this part ALSO works 
     if (!empty($modpass)) { 
      //modpass has some kind of value 


      $staff_name = md5_decrypt($modpass, KU_RANDOMSEED);//is it actually Strider though? 
      //this seems to be the block I am having trouble getting into? 
      //I can not get a value of either of these next two return statements. 
      if ($staff_name == $post_name) { 
       return 'This Works, It\'s me!'; //this is Strider 
      } 
      else { 
       return 'This is '.$staff_name.' attempting to be Strider. This has been logged.'; 
      } 
     } 
     else { 
      return 'Anonymous Test'; 
     } 
    } 
    else { 
     return $post_name; 
    } 

} 

我希望內聯評論能夠解釋發生了什麼,但如果不是,請詢問我的更多信息。

+0

好了,我要感謝的人誰讀這一點,但事實證明,我其實調用的函數不正確。我會發布解決方案。 –

+0

所以它工作正常。 '$ modpass'是空的,所以它跳過了'if'塊並轉到'else'塊。 – Barmar

回答

0

當我打電話從始發類的功能,我用這個代碼:

$post_name = verifyStridersIdentity($post_name,$modpass); 

問題存在是$ modpass實際上並不存在,所以我在空白的發送。

因此,修正通話本來應該是這樣的:

$modpass = ''; 
    if (isset($_POST['modpassword'])) { 
     $modpass = $_POST['modpassword']; 
    } 
    $post_name = verifyStridersIdentity($post_name,$modpass); 
+0

因爲這個原因,不是函數返回'Anonymous test'嗎? – Barmar

+0

正確,這是什麼讓我看看我在調用類中的參數。 –