Whats the best practice in overriding methods?
Especially if we need to add another param?
This is not E_STRICT compliant (adding $soft as second param):
public function delete($id, $soft = false, $cascade = true) {
if ($soft) {
return $this->_softDelete();
}
return parent::delete($id, $cascade);
}
Resulting in:
Declaration of Conversation::delete() should be compatible with that of Model::delete()
I know that one shoudn’t override methods this way (adding-parameters-to-overriden-method-e-strict-observation).
but If one has to, how would one proceed? (without having to remove E_STRICT)
The basic idea was to intercept the normal delete calls without having to rewrite all occurrences of this model method call.
It’s either
E_STRICTcompatibility, or modyfing function signatures. You can’t have both.The solution is usually to use composition instead of inheritance, that is to wrap the object which behaviout you’d like to modify within a new class with different signatures.