0

I'm extending a class:

class Foo extends Bar

I have a method that overrides a method on the parent class:

myMethod($param1, $param2)

I now wish to add an extra param in my child class, but I get a compatibility error. eg.

myMethod($param1, $param2, $param3)

What's the correct way to override a parent's class method so I can change the params?

Please note I am unable to change the parent class in any way.

panthro
  • 22,779
  • 66
  • 183
  • 324
  • Take a look at [this](https://stackoverflow.com/questions/13423494/why-is-overriding-method-parameters-a-violation-of-strict-standards-in-php) SO question. – PeterMader Jun 16 '17 at 12:38
  • you could use an optional parameter? PHP Doesn't support overloading, it does it by allowing optional parameters. – Florian Humblot Jun 16 '17 at 12:38

1 Answers1

0

If you can't change the parent class what about add a setParam3($param3) and getParam3() methods, so before to call myMethod call setParam3 and then in your child class

myMethod($param1, $param2)
{
    $param3 = $this->getparam3();
    // rest of code
}
Nerea
  • 2,107
  • 2
  • 15
  • 14