Method of quantifying PHP7 extended methods which have different number of arguments to parent

60 views Asked by At

I'm upgrading a rather large codebase from PHP 5.6 to PHP 7.2.

There are thousands of places in the code where extended classes contain methods with different number of arguments to the parent method. e.g:

class SomeBaseClass {
    function someMethod($arg1, $arg2, $arg3) {
        ...
    }
}

class SomeOtherClass extends SomeBaseClass {
    function someMethod($arg1) {
      //Doesn't care about the other args, so doesn't specify them as params
    }
}

This causes a fatal error in PHP 7.2.

The fix is obviously to add default values for each argument.

e.g:

 class SomeOtherClass extends SomeBaseClass {
        function someMethod($arg1, $arg2=null, $arg3=null) {
          ...
        }
    }

But this requires that I know where all occurrences of this are.

I'm trying to find a way to either:

  • Relax the error checking so PHP doesn't throw a fatal error when it encounters this.

OR

  • Build out some kind of list which shows exactly which functions are breaking this rule.

I've run a php 7.2 linter on the entire codebase, but it didn't seem to pick up on this issue. I've not been able to find any other tools which would detect this.

Happy to fix them all manually, I just need to be sure I'm getting every single one of them. If anyone knows of an approach to identify them all it would be of huge help.

0

There are 0 answers