0

I've two older extbase Extensions A and B. Ext B extends the Person Model and Controller of A and overwrites the showAction. The extended Model is named "Personcc" while the original Model was named "Person". The showAction looks like

//show action in Controller of EXT A
public function showAction(Vendor\Ext\Domain\Model\Person = $person) {
    ...
}

//show action of extending controller:    
public function showAction(Vendor\Ext\Domain\Model\Personcc = $person) {
    ...
}

Now I have to update the extensions to get them work with PHP7. In PHP5 it works like this, but not in PHP 7. The error is, that the declaration "should be compatible". What can I do besides to totally rebuild Ext B? Is there a way to say PHP7: "please accept this"?

(The example code is a bit abstract, but the problem should be clear and it goes through the whole extension. Without a good idea to overcome this, I think the extension needs to be completely reworked.)

Falk
  • 621
  • 2
  • 9
  • 23

1 Answers1

0

You're breaking Liskov Substitution Principle. In terms of object oriented design this is very bad. In a nutshell, if you have an object, then everywhere you use the object, you shall be able to use a subclass of that object.

It is intended to guarantee semantic interoperability. In other words, it is intended to save your time, and your fellow programmers time, the time spend trying to understand your program. Not only your fellow programmers, but all the tools like static analyzers that should make your own life easier by guarding you from rare errors.

If you think you code should only work with a certain subtype of a common object, then this is a constrain that does not belong to the function's signature. Move it off to the function's body, be it an assertion or an exception, and move on.

sanmai
  • 29,083
  • 12
  • 64
  • 76