6

I have an application in which i have to declare (override) methods inherited from an interface. However, these methods have parameters that are not used in my implementation.

class MyImplementation implements ISomething {

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

  // other methods
  ...
}

How can I mark $bar as unused in the source code, in C++ this is possible.

In other words, how can I do THIS in PHP?

Community
  • 1
  • 1
Michal
  • 1,895
  • 5
  • 33
  • 54
  • 2
    You might try `$bar = $bar;` – RiggsFolly Mar 06 '16 at 16:08
  • Where are you seeing this warning? – Ray Mar 06 '16 at 16:16
  • @RiggsFolly: thanks I'll try it. – Michal Mar 06 '16 at 16:35
  • @Ray: In the majority of PHP development tools, for instance Netbeans – Michal Mar 06 '16 at 16:37
  • @Michal Ah, in an IDE. Based on your comment, this is an IDE specific warning for Netbeans. I'm using Eclipse and it doesn't flag this as an error, warning or notice. However, if I do: `$foo=$foo;` Eclipse complains with a notice "Assignment has no Effect". – Ray Mar 06 '16 at 16:44
  • @Ray Yes, same problem with $bar = $bar – Michal Mar 06 '16 at 16:49
  • `if (($bar = $bar)) {}` TLDR: Double brackets = Ignore this type of warning. http://stackoverflow.com/a/8357990/4621324 – Axalix Mar 06 '16 at 18:18
  • 2
    I would caution against a statement like $bar = $bar, because a) its only purpose is to defeat an IDE warning (which is there for a reason) and b) it decreases the readability/maintainability of the code. I'm assuming OP could just remove the function parameter from this example. PHP shouldn't complain if someone sends an extra param. Alternatively, I would bet you can turn off specific warnings in your IDE. – hcd00045 Jul 10 '17 at 18:40

1 Answers1

-2

if i understand your question correct, you would like to hide the error notices of uninitialized variables in your php script? If that's the case you chould change your error_reporting in php.ini

example: error_reporting=E_ALL & ~E_NOTICE (Show all errors, except for notices)