On Thu, Feb 5, 2015 at 5:14 AM, Andrea Faulds <a...@ajf.me> wrote: > Hi Julien, > >> On 5 Feb 2015, at 12:10, Julien Pauli <jpa...@php.net> wrote: >> >> If we allow larger type, why doesn't such code work ? >> >> interface A { } >> interface B extends A { } >> >> class C { >> public function foo(A $a) { } >> } >> >> class D extends C { >> public function foo(B $a) { } // E_STRICT >> } >> >> This is wrong IMO. > > Well, firstly that’s the wrong way round: inheriting classes can only > *increase* the range of supported values, but you’ve done exactly the > opposite. > > But even if you fixed your code, you’d still have an error. This ispresumably > because doing anything other than simple invariance causes enormous problems > related to compilation order and autoloading, as we discovered with the > Return Types RFC.
I would hardly call them "enormous problems". Just normal problems that I think were easier to avoid than to deal with given my schedule and the time-frame for PHP 7. To chime in regarding allowing contravariant parameter types: I struggle to find use cases for it. I can only think of one use-case and it's flawed: when something has declared an Iterator parameter and you widen it to include Traversable. However, even though Traversable is a parent of Iterator you can't directly call iterator methods on it, so it could break the calling code despite the super-type check passing. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php