Re: RfC: rethink OO inheritance strictness
| From: | Richard Quadling | Date: | Fri, 21 Jul 2006 11:39:52 +0000 |
| Subject: | Re: RfC: rethink OO inheritance strictness | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-24825@lists.php.net to get a copy of this message | ||
I agree and understand that InstanceOf will return true if class B is
a descendent of the class A.
But that doesn't mean that class B is the same as class A.
With overloading, the parameter signature is used to determine which
method is used. The method has to exist within the class heirarchy.
This is what I think the point is.
If I can use a different constructor parameter signature, why can't I
use a different method parameter signature?
They ARE 2 methods! One hides the other. Even if the method's
parameter signature is identical.
If method X is in both class A and class B, using just class B's
instance, you cannot get to class A's method X. Class B has to allow
access via parent::x();
So, why have the same signatures?
On 21/07/06, Stefan Walk <stefan.walk@gmail.com> wrote:
It seems some people are missing the point of the error. "B is a subclass of A" means: everywhere you use A, you can use B instead. ($instance_of_B instanceof A returns true). So, you design a method of yours to accept a parameter of class A, it also accepts B. But if the method signature (number of required parameters) changes, that is not the case anymore. So, you break the inheritance contract, which means that you shouldn't have used inheritance after all.-- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"