2014-07-04 115 views
0

如果我試圖執行下面的代碼。 當用戶未在TS上聯機時,出現錯誤。我想讓它返回false這是可能的嗎?如何刪除錯誤消息

代碼:

$client = $ts3_VirtualServer->clientGetByName($input); 

    if ($client == true) { 

     $TSonline = "true"; 
    } 
    else { 
     $TSonline = "false"; 
    } 
} 
echo $TSonline; 
+0

我想這可能是你在找什麼? http://www.php.net/manual/en/language.exceptions.php – YFP

+0

像'return $ client'? –

+0

return false; ? – Bobot

回答

1

嘗試是這樣的..

try { 

    $client = $ts3_VirtualServer->clientGetByName($input); 
    if ($client){ 
     $tsOnline = true; 
    } else { 
     $tsOnline = false; 
    } 

} catch (Exception $e) { // or whatever exception is available... 

    $tsOnline = false; 

} 
if ($tsOnline){ 
    /* do your stuff */ 
}