Re: inheritance check too strict?
| From: | Zeev Suraski | Date: | Thu, 19 Aug 2010 15:14:35 +0000 |
| Subject: | Re: inheritance check too strict? | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-49457@lists.php.net to get a copy of this message | ||
At 17:04 19/08/2010, Ionut G. Stan wrote:
class Parent
{Child should clearly not be allowed to inherit Parent in the code above, since the signature of Child::foo() is more restrictive than the signature of Parent::foo(). The other way around could work (although I don't recall if we allow it): class Foo {} class Bar extends Foo {} class Parent {public function foo(Foo $foo) {}} class Child {public function foo(Bar $bar) {}} class Foo {} class Bar extends Foo {} All fine until here, but what if... class Taz extends Foo. {} I can't call Child::foo() with an instance of Taz, but I can call Parent::foo() with such an instance. So, I can't use instances of Child wherever instances of Parent would be accepted.
public function foo(Bar $bar){}
}
class Child extends Parent
{
public function foo(Foo $foo){}
}
No issues here - since any Bar object is also a Foo object and would pass the is_a validation of Foo. Again, I don't recall if we allow such signature overrides or not.
Zeev