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 think that we’d probably support full contravariance for 
parameters if we could.

However, we could easily support contravariance in type hint existence, as that 
doesn’t require subclassing checks.

--
Andrea Faulds
http://ajf.me/





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

Reply via email to