PHPGenerics / php-generics-rfc

Mirror of https://wiki.php.net/rfc/generics for easier collaboration
186 stars 1 forks source link

Typed parameters with non-generic types #23

Closed natebrunette closed 6 years ago

natebrunette commented 6 years ago

What happens when you try to set a generic type property to a non-generic type?

class Test
{
    private $box: Box<int>;

    public function setBox(Box $box)
    {
        $this->box = $box;
    }
}
mindplay-dk commented 6 years ago

At run-time, this would probably effectively mean:

class Test
{
    private $box: Box<int>;

    public function setBox(Box<mixed> $box)
    {
        $this->box = $box;
    }
}

The assumption here being that Box must necessarily have a default type-argument - otherwise, type-hinting as just Box wouldn't be valid.