2013-05-03 59 views
-2

我往往會得到很多的這些在PHP中:關閉「缺少參數」警告

Missing argument 2 for ui_alert() 

我知道如何「修復」,但那不是我想要的。我想要的是改變我的錯誤報告設置,使其不顯示。

我喜歡讓我的錯誤報告儘可能廣泛,但對我來說這個警告看起來很荒謬。每次我更新一個函數來處理某個用例時,我都必須更改整個代碼庫。除非我錯過了一些東西,否則它不會引入任何安全問題。

我可以在不關閉任何其他警告的情況下抑制此特定警告嗎?

+0

error_reporting(0); [php.net](http://php.net/manual/en/function.error-reporting.php) – Daniel 2013-05-03 02:13:12

+2

只需修復您的代碼。這是他們的原因! – 2013-05-03 02:13:40

+1

這會關閉其他警告,對吧? – 2013-05-03 02:13:46

回答

1

只是一個默認值添加到你的論點在ui_alert()函數聲明,如null,並警告將消失。

Can I surpress this specific warning without turning off any other warnings?

號您可以關閉所有的警告

有一個錯誤控制運算符(@),使您可以抑制一個表達任何錯誤或警告,但是這是一個不好的做法,它會要求你改變「整個代碼庫」

1

而是改變你的錯誤報告,試圖通過解析null數據..見下面我舉的例子:

function User_Defined ($Argument_1, $Argument_2, $Argument_3){ 
// Perform some functionality 
} 

然後調用你的函數,像這樣:

$I_Want_This_Only = 1; // Added, for the personal hate to spot obvious errors within my code. Without this, it will generate an undefined index. This is a personal preference. 
    User_Defined($I_Want_This_Only,null,null); 

你可以去通過你的每個函數調用並抑制消息。工作示例:

function User_Defined ($Argument_1, $Argument_2, $Argument_3){ 
// Perform some functionality 
} 

    $I_Want_This_Only = 1; // Added, for the personal hate to spot obvious errors within my code. Without this, it will generate an undefined index. This is a personal preference. 
    User_Defined($I_Want_This_Only,null); 

返回錯誤:

Warning: Missing argument 3 for User_Defined()

但呼籲:

@User_Defined($I_Want_This_Only,null); 

不會返回一個錯誤。


在一個理想的世界中,在創建函數接受多個參數是有原因的。如果這些USER_DEFINED功能,那麼爲什麼要建立他們接受更多的參數比你真正想要的嗎?

它在最佳實踐是不要關閉錯誤報告。您可以關閉個別報表,如:

notice OR warning

但這將關閉落在每個錯誤消息的整個報告根據通知或警告標準。所以你可能有潛在的問題,可能會給你的應用程序帶來風險。


您有四個選項。

  • 解決您的bug的代碼,功能是由接受 理由的論點。
  • 通過添加null來填寫參數來調用您的函數。
  • 禁止所有正在產生此問題的函數調用。但 這是它的主要垮臺。
  • 關閉所有warning標準報告。
+0

該解決方案不可擴展。它涉及每次更新函數時更新每個函數調用。 – 2013-05-03 02:15:07

+1

如果你的代碼壞了,你不應該談論可擴展性。 – Kermit 2013-05-03 02:18:10

+0

@AakilFernandes看我的編輯。 – 2013-05-03 02:19:28