On 5 February 2015 at 21:52, Levi Morrison <le...@php.net> wrote:
> To chime in regarding allowing contravariant parameter types: I
> struggle to find use cases for it.

Theoretically it would allow a class to implement two separate
interfaces that would otherwise be incompatible:

interface A {
    function foo();
}

interface B implements A {
    function bar(B $b);
}

interface C implements A {
    function bar(C $c);
};

class D implements B, C {
    // Any object that implements B or C must also
    // implement A, but only the methods from interface A
    // are safe to call inside the method.
    function bar(A $a){
        $a->foo();
    }

    function foo(){...}
}


But I agree, the number of times I've wanted to do this is low.

cheers
Dan

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

Reply via email to