PHP Intelephense - Method is not compatible with child method

Viewed 2012

Consider the following two classes:

class A {
   ...

   testMethod($param = null) {
       ...
   }
}

class B extends A {
   ...

   testMethod($additionalParam, $param = null) {
      ... do something with $additionalParam ...
      parent::testMethod($param);
   }
}

intelephense is raising me an error, that the two methods are not compatible (they are indeed not). My script although runs fine, nonetheless.

Could someone explain to me, why would intelephense be bothered by this design? Wouldn't this design be considered valid? If not, if I would like to extend a method in a sub class, by storing additional information, which I didn't store in the base class, how should I proceed?

1 Answers

Cannot possible overwrite same method with diff parameters, for this try change the name testMethod to testMethodMain or another name in your class B.

Related