At 17:04 19/08/2010, Ionut G. Stan wrote:
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.

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(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

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to