mark
mark

Reputation: 21743

Overriding cake methods in E_STRICT

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.

Upvotes: 0

Views: 219

Answers (1)

Mchl
Mchl

Reputation: 62395

It's either E_STRICT compatibility, 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.

Upvotes: 1

Related Questions