PHP:如何最好地消除有关未使用变量的警告?

Mic*_*hal 8 php warnings unused-variables

我有一个应用程序,我必须在其中声明(覆盖)从接口继承的方法。但是,这些方法具有我的实现中未使用的参数。

class MyImplementation implements ISomething {

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

  // other methods
  ...
}
Run Code Online (Sandbox Code Playgroud)

如何在源代码中将 $bar 标记为未使用,在 C++ 中这是可能的。

换句话说,我怎样才能在 PHP 中做到这一点?

小智 -3

如果我理解你的问题是正确的,你想在你的php脚本中隐藏未初始化变量的错误通知吗?如果是这种情况,您应该更改 php.ini 中的 error_reporting

示例:error_reporting=E_ALL & ~E_NOTICE(显示所有错误,通知除外)