2016-03-06 31 views
3

我有一個應用程序,我必須聲明(覆蓋)從接口繼承的方法。但是,這些方法具有在我的實現中未使用的參數。PHP:我如何最好地關閉未使用變量的警告?

class MyImplementation implements ISomething { 

    public function foo($bar) { 
    // code that does nothing with $bar 
    ... 
    } 

    // other methods 
    ... 
} 

如何在源代碼中將$ bar標記爲未使用,在C++中這是可能的。

換句話說,我怎麼能在PHP中做THIS

+2

你可以嘗試'$欄= $酒吧;' – RiggsFolly

+0

你在哪裏看到這個警告? – Ray

+0

@RiggsFolly:謝謝我會試試看。 – Michal

回答

0
public function foo($bar = null) { 
    // code that does nothing with $bar 
    ... 
} 
0

如果變量沒有值,您可以爲函數參數傳遞的任何變量定義默認值。

就像是:

public function foo($bar = false) { 
    if (!$bar){ // true 
     // your code here 
    } else { 
     // What do you want to do if the $bar variable is not passed? Write here 
    } 
} 
0

如果我明白你的問題是正確的,你想隱藏未初始化變量的在你的PHP腳本錯誤的通知? 如果這是你chould改變你的error_reporting在php.ini

的情況爲例:使用error_reporting = E_ALL &〜E_NOTICE(顯示所有的錯誤,除了提醒)